NetServerGetInfo() Program Example
The NetServerGetInfo() function retrieves current configuration information for the specified server. The following code sample demonstrates how to retrieve current configuration information for a server using a call to the NetServerGetInfo() function. The sample calls NetServerGetInfo(), specifying information level 101 (SERVER_INFO_101). If the call succeeds, the code attempts to identify the type of server. Finally, the sample frees the memory allocated for the information buffer.
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.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, netapi32.lib)
#include <stdio.h>
#include <windows.h>
#include <lm.h>
int wmain(int argc, wchar_t *argv[ ])
{
DWORD dwLevel = 101;
LPSERVER_INFO_101 pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
if (argc != 2)
{
fwprintf_s(stderr, LUsage: %s [\\\\ServerName]\n, argv[0]);
wprintf(LExample: %s \\\\Bigbroserv\n, argv[0]);
exit(1);
}
// The server is not the default local computer.
if (argc == 2)
pszServerName = (LPTSTR) argv[1];
// Call the NetServerGetInfo() function, specifying level 101.
nStatus = NetServerGetInfo(pszServerName,dwLevel,(LPBYTE *)&pBuf);
// If the call succeeds,
if (nStatus == NERR_Success)
{
wprintf(LNetServerGetInfo() is OK!\n);
// Check for the type of server.
if ((pBuf->sv101_type & SV_TYPE_DOMAIN_CTRL) || (pBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) || (pBuf->sv101_type & SV_TYPE_SERVER_NT))
wprintf(LThis is a server\n);
else
wprintf(LThis is a workstation\n);
}
// Otherwise, print the system error.
else
{
wprintf(LNetServerGetInfo() failed!\n);
fwprintf_s(stderr, LA system error has occurred: %d\n, nStatus);
}
// Free the allocated memory.
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
Build and run the project. The following screenshot is a sample output.
