Platform SDK: Network Management

NetQueryDisplayInformation

The NetQueryDisplayInformation function returns user account, computer, or group account information. Call this function to quickly enumerate account information for display in user interfaces.

Security Requirements

Windows NT: No special group membership is required to successfully execute the NetQueryDisplayInformation function.

Windows 2000: If you call this function on a Windows 2000 domain controller that is running Active Directory, access is allowed or denied based on the access-control list (ACL) for the securable object. The default ACL permits all authenticated users and members of the "Pre-Windows 2000 compatible access" group to view the information. By default, the "Pre-Windows 2000 compatible access" group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous access.

If you call this function on a Windows 2000 member server or workstation, all authenticated users can view the information. Anonymous access is also permitted if the RestrictAnonymous policy setting allows anonymous access.

For more information about restricting anonymous access, see Security Requirements for the Network Management Functions.

NET_API_STATUS NetQueryDisplayInformation(
  LPCWSTR ServerName,            
  DWORD Level,                   
  DWORD Index,                   
  DWORD EntriesRequested,        
  DWORD PreferredMaximumLength,  
  LPDWORD ReturnedEntryCount,    
  PVOID *SortedBuffer            
);

Parameters

ServerName
[in] Pointer to a constant null-terminated Unicode 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.
Value Meaning
1 Return user account information. The SortedBuffer parameter points to an array of NET_DISPLAY_USER structures.
2 Return individual computer information. The SortedBuffer parameter points to an array of NET_DISPLAY_MACHINE structures.
3 Return group account information. The SortedBuffer parameter points to an array of NET_DISPLAY_GROUP structures.

Index
[in] Specifies the index of the first entry for which to retrieve information. Specify zero to retrieve account information beginning with the first display information entry. For more information, see the following Remarks section.
EntriesRequested
[in] Specifies the maximum number of entries for which to retrieve information.
PreferredMaximumLength
[in] Specifies the preferred maximum size, in bytes, of the system-allocated buffer returned in the SortedBuffer parameter.
ReturnedEntryCount
[out] Pointer to a DWORD value that receives the number of entries in the buffer returned in the SortedBuffer parameter. If this parameter is zero, there are no entries with an index as large as that specified. Entries may be returned when the function's return value is either NERR_Success or ERROR_MORE_DATA.
SortedBuffer
[out] Pointer to a buffer that receives a pointer to a system-allocated buffer specifying a sorted list of the requested information. The format of this data depends on the value of the Level parameter. Because this buffer is allocated by the system, it must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA.

Return Values

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value is 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 Level parameter specifies an invalid value.
ERROR_MORE_DATA More entries are available. That is, the last entry returned in the SortedBuffer parameter is not the last entry available. To retrieve additional entries, call NetQueryDisplayInformation again with the Index parameter set to the value returned in the next_index member of the last entry in SortedBuffer.

Remarks

The NetQueryDisplayInformation and NetGetDisplayInformationIndex functions provide an efficient mechanism for enumerating user and group accounts. When possible, use these functions instead of the NetUserEnum function or the NetGroupEnum function.

Windows 2000: Calling the NetQueryDisplayInformation function to enumerate account information on a Windows 2000 domain can be costly in terms of performance. If you are programming for Active Directory, you may be able to use methods on the IDirectorySearch interface to make paged queries against the domain. For more information, see IDirectorySearch::SetSearchPreference and IDirectorySearch::ExecuteSearch.

The following code sample demonstrates how to return group account information using a call to the NetQueryDisplayInformation function. If the user specifies a server name, the sample first calls the MultiByteToWideChar function to convert the name to Unicode. The sample calls NetQueryDisplayInformation, specifying information level 3 (NET_DISPLAY_GROUP) to retrieve group account information. If there are entries to return, the sample returns the data in chunks of 25 bytes (for demonstration purposes) and prints the group information. Finally, the code sample frees the memory allocated for the information buffer.

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>

void main( int argc, char *argv[ ] )
{
   PNET_DISPLAY_GROUP pBuff, p;
   DWORD res, dwRec, i = 0;
   //
   // You can pass a NULL or empty string
   //  to retrieve the local information.
   //
   TCHAR szServer[255]=TEXT(""); 

   if(argc > 1) 
      //
      // Check to see if a server name was passed;
      //  if so, convert it to Unicode.
      //
      MultiByteToWideChar(CP_ACP, 0, argv[1], -1, szServer, 255); 

   do // begin do
   { 
      //
      // Call the NetQueryDisplayInformation function;
      //   specify information level 3 (group account information).
      //  This code returns the data in chunks of 25 bytes to 
      //  demonstrate how to make the request over and over again.
      //
      res = NetQueryDisplayInformation(szServer, 3, i, 1000, 25, &dwRec, &pBuff);
      //
      // If the call succeeds,
      //
      if((res==ERROR_SUCCESS) || (res==ERROR_MORE_DATA))
      {
         p = pBuff;
         for(;dwRec>0;dwRec--)
         {
            //
            // Print the retrieved group information.
            //
            printf("Name:      %S\n"
                  "Comment:   %S\n"
                  "Group ID:  %u\n"
                  "Attributs: %u\n"
                  "--------------------------------\n",
                  p->grpi3_name,
                  p->grpi3_comment,
                  p->grpi3_group_id,
                  p->grpi3_attributes);
            //
            // If there is more data, set the index.
            //
            i = p->grpi3_next_index;
            p++;
         }
         //
         // Free the allocated memory.
         //
         NetApiBufferFree(pBuff);
      }
      else
         printf("Error: %u\n", res);
   //
   // Continue while there is more data.
   //
   } while (res==ERROR_MORE_DATA); // end do
   return;
}

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Lmaccess.h; include Lm.h.
  Library: Use Netapi32.lib.

See Also

Network Management Overview, Network Management Functions, Get Functions, NET_DISPLAY_GROUP, NET_DISPLAY_MACHINE, NET_DISPLAY_USER, NetGetDisplayInformationIndex, NetUserEnum, NetGroupEnum