Platform SDK: Network Management

NetServerGetInfo

The NetServerGetInfo function retrieves current configuration information for the specified server.

Security Requirements

Only the Administrators or Accounts Operators local group, or those with Communication, 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.

Windows NT/2000: The parameter order is as follows.

NET_API_STATUS NetServerGetInfo(
  LPWSTR servername,  
  DWORD level,        
  LPBYTE *bufptr      
);

Windows 95/98: The calling application must use the cbBuffer parameter to specify the size, in bytes, of the information buffer pointed to by the pbBuffer parameter. If the length of the buffer is not large enough to hold all of the data, the function returns as much as will fit in the buffer. The function returns the total number of bytes of information available in the pcbTotalAvail parameter. The parameter list is as follows.

extern API_FUNCTION
 NetServerGetInfo(
  const char FAR * pszServer,        
  short sLevel,                      
  char FAR * pbBuffer,               
  unsigned short cbBuffer,           
  unsigned short FAR * pcbTotalAvail 
);

Parameters

servername
[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
level
[in] Specifies the information level of the data. This parameter can be one of the following values.

Windows NT/2000: The following levels are valid on all platforms.
Value Meaning
100 Return the server name and platform information. The bufptr parameter points to a SERVER_INFO_100 structure.
101 Return the server name, type, and associated software. The bufptr parameter points to a SERVER_INFO_101 structure.
102 Return the server name, type, associated software, and other attributes. The bufptr parameter points to a SERVER_INFO_102 structure.

Windows 95/98: The following levels are valid.
Value Meaning
1 Return the server name, type, and associated software. The pbBuffer parameter points to a server_info_1 structure.
50 Return the server name, type, associated software, and other attributes. The pbBuffer parameter points to a server_info_50 structure.

bufptr
[out] Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter.

Windows NT/2000: This buffer is allocated by the system and must be freed using the NetApiBufferFree function.

Windows 95/98: The caller must allocate and deallocate this buffer.

Return Values

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.

Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_LEVEL The value specified for the level parameter is invalid.
ERROR_INVALID_PARAMETER The specified parameter is invalid.
ERROR_NOT_ENOUGH_MEMORY Insufficient memory is available.

Remarks

Windows 95/98: See the NetServerGetInfo Sample (Windows 95/98) topic to view a code sample that demonstrates how to use the NetServerGetInfo function.

Windows NT/2000: 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

#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 = 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;
}

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.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Lmserver.h (Windows NT/2000) or Svrapi.h (Windows 95/98); include Lm.h (Windows NT/2000).
  Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows 95/98).

See Also

Network Management Overview, Network Management Functions, Server Functions, NetServerSetInfo, SERVER_INFO_100, SERVER_INFO_101, SERVER_INFO_102, server_info_1, server_info_50, NetRemoteComputerSupports