The NetUserAdd function adds a user account and assigns a password and privilege level.
NET_API_STATUS NET_API_FUNCTION NetUserAdd( LPCWSTR servername, DWORD level, LPBYTE buf, LPDWORD parm_err );
Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined.
Specifies the information level of the data. This parameter can be one of the following values.
Specifies information about the user account. The buf parameter points to a
When you specify this level, the call initializes certain attributes to their default values. For more information, see the following Remarks section.
||Specifies level one information and additional attributes about the user account. The buf parameter points to a USER_INFO_2 structure.|
||Specifies level two information and additional attributes about the user account. This level is valid only on servers. The buf parameter points to a USER_INFO_3 structure. Note that it is recommended that you use USER_INFO_4 instead.|
Specifies level two information and additional attributes about the user account. This level is valid only on servers. The buf parameter points to a
Windows 2000: This level is not supported.
Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more information, see Network Management Function Buffers.
Pointer to a value that receives the index of the first member of the user information structure that causes ERROR_INVALID_PARAMETER. If this parameter is NULL, the index is not returned on error. For more information, see the NetUserSetInfo function.
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
||The user does not have access to the requested information.|
||The computer name is invalid.|
||The operation is allowed only on the primary domain controller of the domain.|
||The group already exists.|
||The user account already exists.|
||The password is shorter than required. (The password could also be too long, be too recent in its change history, not have enough unique characters, or not meet another password policy requirement.)|
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management user functions. For more information, see IADsUser and IADsComputer.
If you call this function on a domain controller that is running Active Directory, access is allowed or denied based on the access control list (ACL) for the securable object. The default ACL permits only Domain Admins and Account Operators to call this function. On a member server or workstation, only Administrators and Power Users can call this function. For more information, see Security Requirements for the Network Management Functions. For more information on ACLs, ACEs, and access tokens, see Access Control Model.
The security descriptor of the user container is used to perform the access check for this function. The caller must be able to create child objects of the user class.
Server users must use a system in which the server creates a system account for the new user. The creation of this account is controlled by several parameters in the server's LanMan.ini file.
If the newly added user already exists as a system user, the usri1_home_dir member of the USER_INFO_1 structure is ignored.
When you call the NetUserAdd function and specify information level 1, the call initializes the additional members in the USER_INFO_2, USER_INFO_3, and USER_INFO_4 structures to their default values. You can change the default values by making subsequent calls to the NetUserSetInfo function. The default values supplied are listed following. (The prefix usriX indicates that the member can begin with multiple prefixes, for example, usri2_ or usri4_.)
|usriX_full_name||None (null string)|
|usriX_usr_comment||None (null string)|
|usriX_parms||None (null string)|
|usriX_workstations||All (null string)|
|usriX_logon_hours||Logon allowed at any time (each element 0xFF; all bits set to 1)|
|usriX_logon_server||Any domain controller (\\*)|
User account names are limited to 20 characters and group names are limited to 256 characters. In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters: ", /, , [, ], :, |, <, >, +, =, ;, ?, *. Names also cannot include characters in the range 1-31, which are nonprintable.
The following code sample demonstrates how to add a user account and assign a privilege level using a call to the NetUserAdd function. The code sample fills in the members of the USER_INFO_1 structure and calls NetUserAdd, specifying information level 1.
#ifndef UNICODE #define UNICODE #endif #pragma comment(lib, "netapi32.lib")
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|
|Header||lmaccess.h (include Lm.h)|