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.
Then, add the source file and give it a suitable name.
Then, add the following source code.
#pragma comment(lib, "netapi32.lib")
int wmain(int argc, wchar_t *argv)
DWORD dwLevel = 1005;
if (argc != 3)
fwprintf_s(stderr, L"Usage: %s \\\\ServerName Comment\n", argv);
wprintf(L"Example: %s \\\\Bigbrosvr \"This is a crap server\"\n", argv);
// Fill in SERVER_INFO_1005 structure member.
si.sv1005_comment = (LPTSTR) argv;
// Call the NetServerSetInfo() function, specifying level 1005.
nStatus = NetServerSetInfo(argv,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);
fwprintf_s(stderr, L"A system error has occurred: %d\n", nStatus);
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.
Then, verify our previous action.
MSDN Network Management Reference
The following links describe the network management functions and their associated data structures for Win32 programming.