NetServerGetInfo function (lmserver.h)
The NetServerGetInfo function retrieves current configuration information for the specified server.
Syntax
NET_API_STATUS NET_API_FUNCTION NetServerGetInfo(
[in] LMSTR servername,
[in] DWORD level,
[out] LPBYTE *bufptr
);
Parameters
[in] servername
Pointer to a string that specifies the name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
[in] level
Specifies the information level of the data. This parameter can be one of the following values.
Value | Meaning |
---|---|
|
Return the server name and platform information. The bufptr parameter points to a SERVER_INFO_100 structure. |
|
Return the server name, type, and associated software. The bufptr parameter points to a SERVER_INFO_101 structure. |
|
Return the server name, type, associated software, and other attributes. The bufptr parameter points to a SERVER_INFO_102 structure. |
[out] bufptr
Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter.
This buffer is allocated by the system and must be freed using the NetApiBufferFree function.
Return value
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
Return code | Description |
---|---|
|
The user does not have access to the requested information. |
|
The value specified for the level parameter is invalid. |
|
The specified parameter is invalid. |
|
Insufficient memory is available. |
|
The server service is not started. |
Remarks
Only the Administrators or Server Operators local group, or those with Print or Server Operator group membership, can successfully execute the NetServerGetInfo function at level 102. No special group membership is required for level 100 or level 101 calls.
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management server functions. For more information, see IADsComputer.
Examples
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.
#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(stderr, L"Usage: %s [\\\\ServerName]\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)
{
//
// 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))
printf("This is a server\n");
else
printf("This is a workstation\n");
}
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | lmserver.h (include Lm.h) |
Library | Netapi32.lib |
DLL | Netapi32.dll |