The Win32 Network Management APIs 15

 

 

 

 

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example

 

The following code fragment illustrates how to associate a comment with a user by calling the NetUserSetInfo() function. The USER_INFO_1007 topic contains additional information.

 

#define COMMENT L"This is my Comment Text for the user"

USER_INFO_1007 usriComment;

// Set the usri1007_comment member to point to a valid Unicode string.

// SERVER and USERNAME can be hard-coded strings or pointers to Unicode strings.

usriComment.usri1007_comment = COMMENT;

 

netRet = NetUserSetInfo( SERVER, USERNAME, 1007, (LPBYTE)&usriComment, NULL );

 

if( netRet == NERR_Success )

    wprintf(L"Success with level 1007!\n");

else

    wprintf(L"ERROR: %d returned from NetUserSetInfo level 1007\n", netRet);

 

A working sample program is given below. Firstly we are going to verify the user description setting before we run the program. In this case we just using a local user, mike spoon on the computer named nazuri.

 

User account management snap-in for Windows local computer

 

Next we create a new empty Win32 console application project.

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example: Creating new C++ Win32 console application project in Visual C++ .NET

 

Then, add the source file and give it a suitable name.

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example: Adding new C++ source file for the source code

 

Then, add the following source code.

 

#include <windows.h>

// INCL_NET includes all LAN Manager headers if necessary

// #define INCL_NET

#include <lm.h>

#include <stdio.h>

 

// Optionally, use the following #pragma if you do not include

// the library through the Visual Studio setting

// example: #pragma comment(linker, "<linker options>")

#pragma comment(lib, "netapi32.lib")

 

// In this case, we are testing the local user

#define SERVER L"nazuri"

#define USERNAME L"mike spoon"

 

#define COMMENT L"This is my Comment Text for the user"

 

int wmain()

{

      DWORD netRet;

      USER_INFO_1007 usriComment;

     

      // Set the usri1007_comment member to point to a valid Unicode string.

      // SERVER and USERNAME can be hard-coded strings or pointers to Unicode strings.

      usriComment.usri1007_comment = COMMENT;

      netRet = NetUserSetInfo(SERVER, USERNAME, 1007, (LPBYTE)&usriComment, NULL);

     

      if(netRet == NERR_Success)

            wprintf(L"Success with level 1007!\n");

      else

            wprintf(L"ERROR: %d returned from NetUserSetInfo() level 1007\n", netRet);

 

      return 0;

}

 

Build and run the project.

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example: a sample console output

 

Verify the action. The description has been changed as shown below.

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example: the user account description has been set programmatically

 

 

Setting the User Comment (Description) Field, Level 1007 Code Snippet Example: The user account description

 

 

 

 

< Win32 Network Management APIs 14 | Win32 Network Management APIs | Win32 Programming | Win32 Network Management APIs 16 >