Network Management Function ...


NetServerGetInfo Function

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

Syntax

C++
NET_API_STATUS NetServerGetInfo(
  __in   LPWSTR servername,
  __in   DWORD level,
  __out  LPBYTE *bufptr
);

Parameters

servername [in]

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.

level [in]

Specifies the information level of the data. This parameter can be one of the following values.

ValueMeaning
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.

 

bufptr [out]

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 codeDescription
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

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

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderLmserver.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll

See Also

Network Management Overview
Network Management Functions
Server Functions
NetServerSetInfo
SERVER_INFO_100
SERVER_INFO_101
SERVER_INFO_102
NetRemoteComputerSupports

Send comments about this topic to Microsoft

Build date: 9/17/2009

Tags :


Page view tracker