The Win32 Network Management APIs 51






NetServerSetInfo() Program Example


The NetServerSetInfo() function sets a server's operating parameters; it can set them individually or collectively. The information is stored in a way that allows it to remain in effect after the system has been reinitialized. The following code sample demonstrates how to call the NetServerSetInfo() function. The sample calls NetServerSetInfo(), specifying the level parameter as 1005 (required) to set the sv1005_comment member of the SERVER_INFO_1005 structure.

Create a new empty Win32 console application project. Give the project name and change the project location is needed.


NetServerSetInfo() Program Example: Creating new C++ Win32 console application project in Visual C++ .NET


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


NetServerSetInfo() Program Example: Adding new C++ source  file for the C++ source code


Then, add the following source code.


#ifndef UNICODE

#define UNICODE



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


#include <stdio.h>

#include <windows.h>

#include <lm.h>


int wmain(int argc, wchar_t *argv[])


   DWORD dwLevel = 1005;

   SERVER_INFO_1005 si;

   NET_API_STATUS nStatus;


   if (argc != 3)


      fwprintf_s(stderr, L"Usage: %s \\\\ServerName Comment\n", argv[0]);

      wprintf(L"Example: %s \\\\Bigbrosvr \"This is a crap server\"\n", argv[0]);




   // Fill in SERVER_INFO_1005 structure member.

   si.sv1005_comment = (LPTSTR) argv[2];

   // Call the NetServerSetInfo() function, specifying level 1005.

   nStatus = NetServerSetInfo(argv[1],dwLevel,(LPBYTE)&si,NULL);

   // Display the result of the call.

   if (nStatus == NERR_Success)


         wprintf(L"NetServerSetInfo() is OK!\n");

         fwprintf_s(stderr, L"Comment reset\n", argv[2]);




         wprintf(L"NetServerSetInfo() failed!\n");

         fwprintf_s(stderr, L"A system error has occurred: %d\n", nStatus);


   return 0;



We are going to set the server description (however, in this case we just test it against the local Win XP Pro SP2). Build and run the project. The following screenshot is a sample output.


NetServerSetInfo() Program Example: Server or workstation description


NetServerSetInfo() Program Example: A sample program output


Then, verify our previous action.


NetServerSetInfo() Program Example: Server/workstation description was changed programmatically


MSDN Network Management Reference


The following links describe the network management functions and their associated data structures for Win32 programming.


  1. Network Management Functions
  2. Network Management Structures
  3. Network Management Macros
  4. Network Management Error Codes





< Win32 Network Management APIs 50 | Win32 Network Management APIs | Win32 Programming | Windows Access Control List (ACL) Programming >