Platform SDK: Network Management |
The NetUserSetInfo function sets the parameters of a user account.
Windows NT: Only members of the Administrators or Account Operators local group can successfully execute the NetUserSetInfo function on a remote server or on a computer that has local security enabled. A user can call NetUserSetInfo to set certain information on his or her own account. For more information about permissions required to set user elements, see the following Remarks section.
Windows 2000: If you call this function on a Windows 2000 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 Administrators and account operators to call this function. On a member server or workstation, only Administrators and account operators can call this function. For more information, see Security Requirements for the Network Management Functions.
NET_API_STATUS NetUserSetInfo( LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE buf, LPDWORD parm_err );
Value | Meaning |
---|---|
0 | Specifies the user account name. The buf parameter points to a USER_INFO_0 structure. Use this structure to specify a new group name. For more information, see the following Remarks section. |
1 | Specifies detailed information about the user account. The buf parameter points to a USER_INFO_1 structure. |
2 | Specifies level one information and additional attributes about the user account. The buf parameter points to a USER_INFO_2 structure. |
3 | Specifies level two information and additional attributes about the user account. This level is valid only on Windows NT/Windows 2000 servers. The buf parameter points to a USER_INFO_3 structure. |
21 | Specifies a one-way encrypted LAN Manager 2.x-compatible password. The buf parameter points to a USER_INFO_21 structure. |
22 | Specifies detailed information about the user account. The buf parameter points to a USER_INFO_22 structure. |
1003 | Specifies a user password. The buf parameter points to a USER_INFO_1003 structure. |
1005 | Specifies a user privilege level. The buf parameter points to a USER_INFO_1005 structure. |
1006 | Specifies the path of the home directory for the user. The buf parameter points to a USER_INFO_1006 structure. |
1007 | Specifies a comment to associate with the user account. The buf parameter points to a USER_INFO_1007 structure. |
1008 | Specifies user account attributes. The buf parameter points to a USER_INFO_1008 structure. |
1009 | Specifies the path for the user's logon script file. The buf parameter points to a USER_INFO_1009 structure. |
1010 | Specifies the user's operator privileges. The buf parameter points to a USER_INFO_1010 structure. |
1011 | Specifies the full name of the user. The buf parameter points to a USER_INFO_1011 structure. |
1012 | Specifies a comment to associate with the user. The buf parameter points to a USER_INFO_1012 structure. |
1014 | Specifies the names of workstations from which the user can log on. The buf parameter points to a USER_INFO_1014 structure. |
1017 | Specifies when the user account expires. The buf parameter points to a USER_INFO_1017 structure. |
1020 | Specifies the times during which the user can log on. The buf parameter points to a USER_INFO_1020 structure. |
1024 | Specifies the user's country/region code. The buf parameter points to a USER_INFO_1024 structure. |
1051 | Specifies the relative identifier of a global group that represents the enrolled user. The buf parameter points to a USER_INFO_1051 structure. |
1052 | Specifies the path to a network user's profile. The buf parameter points to a USER_INFO_1052 structure. |
1053 | Specifies the drive letter assigned to the user's home directory. The buf parameter points to a USER_INFO_1053 structure. |
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.
Value | Meaning |
---|---|
ERROR_ACCESS_DENIED | The user does not have access to the requested information. |
ERROR_INVALID_PARAMETER | One of the function parameters is invalid. For more information, see the following Remarks section. |
NERR_InvalidComputer | The computer name is invalid. |
NERR_NotPrimary | The operation is allowed only on the primary domain controller of the domain. |
NERR_SpeGroupOp | The operation is not allowed on specified special groups, which are user groups, admin groups, local groups, or guest groups. |
NERR_LastAdmin | The operation is not allowed on the last administrative account. |
NERR_BadPassword | The share name or password is invalid. |
NERR_PasswordTooShort | 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.) |
NERR_UserNotFound | The user name could not be found. |
See the end of this Remarks section for a code sample that demonstrates use of the NetUserSetInfo function.
Only users or applications having administrative privileges can call the NetUserSetInfo function to change a user's password. When an administrator calls NetUserSetInfo, the only restriction applied is that the new password length must be consistent with system modals. A user or application that knows a user's current password can call the NetUserChangePassword function to change the password.
Members of the Administrators local group can set any modifiable user account elements. All users can set the usri2_country_code member of the USER_INFO_2 structure (and the usri1024_country_code member of the USER_INFO_1024 structure) for their own accounts.
A member of the Account Operator's local group cannot set details for an Administrators class account, give an existing account Administrator privilege, or change the operator privilege of any account. If you attempt to change the privilege level or disable the last account with Administrator privilege in the security database, the NetUserSetInfo function fails and returns NERR_LastAdmin.
The correct way to specify the new name for an account is to call NetUserSetInfo with USER_INFO_0 and to specify the new value using the usri0_name member. If you call NetUserSetInfo with other information levels and specify a value using a usriX_name member, the value is ignored.
Note that calls to NetUserSetInfo can change the home directory only for user accounts that the network server creates.
If the NetUserSetInfo function returns ERROR_INVALID_PARAMETER, you can use the parm_err parameter to indicate the first member of the user information structure that is invalid. (A user information structure begins with USER_INFO_ and its format is specified by the level parameter.) The following table lists the values that can be returned in the parm_err parameter and the corresponding structure member that is in error. (The prefix usri*_ indicates that the member can begin with multiple prefixes, for example, usri10_ or usri1003_.)
Value | Member |
---|---|
USER_NAME_PARMNUM | usri*_name |
USER_PASSWORD_PARMNUM | usri*_password |
USER_PASSWORD_AGE_PARMNUM | usri*_password_age |
USER_PRIV_PARMNUM | usri*_priv |
USER_HOME_DIR_PARMNUM | usri*_home_dir |
USER_COMMENT_PARMNUM | usri*_comment |
USER_FLAGS_PARMNUM | usri*_flags |
USER_SCRIPT_PATH_PARMNUM | usri*_script_path |
USER_AUTH_FLAGS_PARMNUM | usri*_auth_flags |
USER_FULL_NAME_PARMNUM | usri*_full_name |
USER_USR_COMMENT_PARMNUM | usri*_usr_comment |
USER_PARMS_PARMNUM | usri*_parms |
USER_WORKSTATIONS_PARMNUM | usri*_workstations |
USER_LAST_LOGON_PARMNUM | usri*_last_logon |
USER_LAST_LOGOFF_PARMNUM | usri*_last_logoff |
USER_ACCT_EXPIRES_PARMNUM | usri*_acct_expires |
USER_MAX_STORAGE_PARMNUM | usri*_max_storage |
USER_UNITS_PER_WEEK_PARMNUM | usri*_units_per_week |
USER_LOGON_HOURS_PARMNUM | usri*_logon_hours |
USER_PAD_PW_COUNT_PARMNUM | usri*_bad_pw_count |
USER_NUM_LOGONS_PARMNUM | usri*_num_logons |
USER_LOGON_SERVER_PARMNUM | usri*_logon_server |
USER_COUNTRY_CODE_PARMNUM | usri*_country_code |
USER_CODE_PAGE_PARMNUM | usri*_code_page |
USER_PRIMARY_GROUP_PARMNUM | usri*_primary_group_id |
USER_PROFILE_PARMNUM | usri*_profile |
USER_HOME_DIR_DRIVE_PARMNUM | usri*_home_dir_drive |
The following code sample demonstrates how to disable a user account with a call to the NetUserSetInfo function. The code sample fills in the usri1008_flags member of the USER_INFO_1008 structure, specifying the value UF_ACCOUNTDISABLE. Then the sample calls NetUserSetInfo, specifying information level 0.
#ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <windows.h> #include <lm.h> int wmain(int argc, wchar_t *argv[]) { DWORD dwLevel = 1008; USER_INFO_1008 ui; NET_API_STATUS nStatus; if (argc != 3) { fwprintf(stderr, L"Usage: %s \\\\ServerName UserName\n", argv[0]); exit(1); } // Fill in the USER_INFO_1008 structure member. // UF_SCRIPT: required for LAN Manager 2.0 and // Windows NT/Windows 2000. // ui.usri1008_flags = UF_SCRIPT | UF_ACCOUNTDISABLE; // // Call the NetUserSetInfo function // to disable the account, specifying level 1008. // nStatus = NetUserSetInfo(argv[1], argv[2], dwLevel, (LPBYTE)&ui, NULL); // // Display the result of the call. // if (nStatus == NERR_Success) fwprintf(stderr, L"User account %s has been disabled\n", argv[2]); else fprintf(stderr, "A system error has occurred: %d\n", nStatus); return 0; }
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.
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Unsupported.
Header: Declared in Lmaccess.h; include Lm.h.
Library: Use Netapi32.lib.
Network Management Overview, Network Management Functions, User Functions, NetUserGetInfo, USER_INFO_0, USER_INFO_1, USER_INFO_2, USER_INFO_3, USER_INFO_21, USER_INFO_22, USER_INFO_1003, USER_INFO_1005, USER_INFO_1006, USER_INFO_1007, USER_INFO_1008, USER_INFO_1009, USER_INFO_1010, USER_INFO_1011, USER_INFO_1012, USER_INFO_1013, USER_INFO_1014, USER_INFO_1017, USER_INFO_1020, USER_INFO_1024, USER_INFO_1051, USER_INFO_1052, USER_INFO_1053