Changing Elements of User Information Code Snippet Example
The network management functions provide a variety of information levels to assist in changing user information. Some levels require administrative privileges to execute successfully. The following code example demonstrates how to change several elements of user information by calling the NetUserSetInfo() function. The code uses various network management information structures. When changing user information, it is best to use the specific level for that piece of information. This prevents the accidental resetting of unrelated information when using the lower level values. Setting some of the more commonly used levels is illustrated in the following code samples:
All code fragments assume that the user has defined the UNICODE compile directive (or the set through the Visual Studio project’s setting as shown in the following Figure),

And includes the appropriate SDK header files, as follows:
#include <windows.h>
// INCL_NET includes all LAN Manager headers if necessary
// #define INCL_NET
#include <lm.h>
#include <stdio.h>
#pragma comment(lib, netapi32.lib)
#define SERVER Ltest_server_name
#define USERNAME Ltest_user_name
DWORD netRet = 0;
Setting the User Password, Level 1003 Code Snippet Example
The following code fragment illustrates how to set a user's password to a known value with a call to the NetUserSetInfo() function. The USER_INFO_1003 topic contains additional information.
#define PASSWORD Lnew_password
USER_INFO_1003 usriSetPassword;
// Set the usri1003_password member to point to a valid Unicode string.
// SERVER and USERNAME can be hard-coded strings or pointers to Unicode strings.
usriSetPassword.usri1003_password = PASSWORD;
netRet = NetUserSetInfo(SERVER, USERNAME, 1003, (LPBYTE)&usriSetPassword, NULL);
if(netRet == NERR_Success)
wprintf(LSuccess with level 1003!\n);
else
wprintf(LERROR: %d returned from NetUserSetInfo level 1003\n, netRet);
Setting the User Privilege, Level 1005 Code Snippet Example
The following code fragment illustrates how to specify the level of privilege assigned to a user with a call to the NetUserSetInfo() function. The USER_INFO_1005 topic contains additional information.
USER_INFO_1005 usriPriv;
// Set the usri1005_priv member to the appropriate value.
// SERVER and USERNAME can be hard-coded strings or pointers to Unicode strings.
usriPriv.usri1005_priv = USER_PRIV_USER;
netRet = NetUserSetInfo( SERVER, USERNAME, 1005, (LPBYTE)&usriPriv, NULL );
if( netRet == NERR_Success )
wprintf(LSuccess with level 1005!\n);
else
wprintf(LERROR: %d returned from NetUserSetInfo level 1005\n, netRet);
Setting the User Home Directory, Level 1006 Code Snippet Example
The following code fragment illustrates how to specify the path of a user's home directory with a call to the NetUserSetInfo() function. The directory can be a hard-coded path or a valid Unicode path. The USER_INFO_1006 topic contains additional information.
#define HOMEDIR LC:\\USER\USER_PATH
USER_INFO_1006 usriHomeDir;
// Set the usri1006_home_dir member to point to a valid Unicode string.
// SERVER and USERNAME can be hard-coded strings or pointers to Unicode strings.
usriHomeDir.usri1006_home_dir = HOMEDIR;
netRet = NetUserSetInfo( SERVER, USERNAME, 1006, (LPBYTE)&usriHomeDir, NULL );
if( netRet == NERR_Success )
wprintf(LSuccess with level 1006!\n);
else
wprintf(LERROR: %d returned from NetUserSetInfo level 1006\n, netRet);