How to Look Up a User's Full Name

Last reviewed: September 29, 1995
Article ID: Q119670
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) for Windows NT, versions 3.1 and 3.5

SUMMARY

Windows NT workstations can be organized into a domain, which is a collection of computers on a Windows NT Advanced Server network. The domain administrator maintains centralized user and group account information.

MORE INFORMATION

To find the full name of a user if you have the user name and domain name:

  1. Convert the user name and domain name to Unicode, if they are not already Unicode strings. This is a requirement of the ported LAN Manager APIs that are used in the following steps.

  2. Look up the name of the domain controller (DC) for the domain name by calling NetServerEnum().

  3. Look up the user name by calling NetUserGetInfo()

  4. Convert the full user name to ANSI, unless the program is expecting to work with Unicode strings.

The sample code below is a function that takes a user name and a domain name as the first two arguments and returns the user's full name in the third argument.

For information on how to get the current user and domain, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q111544

TITLE     : Looking Up the Current User and Domain

Sample Code

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

   /********************************************************************\
   * Function: GetFullName( char *UserName, char *Domain, char *dest ); *
   *                                                                    *
   * Parameters:                                                        *
   *    UserName: the user name                                         *
   *    Domain  : the domain to which the user belongs                  *
   *    dest    : receives the user's full name                         *
   *                                                                    *
   \********************************************************************/

   BOOL GetFullName(char *UserName, char *Domain, char *dest)
   {
      WCHAR  wszUserName[256];           // Unicode user name
      WCHAR  wszDomain[256];
      LPBYTE ComputerName;

      struct _SERVER_INFO_100 *si100;   // Server structure
      struct _USER_INFO_2 *ui;          // User structure

      // Convert ASCII user name and domain to Unicode.

      MultiByteToWideChar( CP_ACP, 0, UserName,
         strlen(UserName)+1, wszUserName, sizeof(wszUserName) );
      MultiByteToWideChar( CP_ACP, 0, Domain,
         strlen(Domain)+1, wszDomain, sizeof(wszDomain) );

      // Get the computer name of a DC for the specified domain.

      NetGetDCName( NULL, wszDomain, &ComputerName );

      // Look up the user on the DC.

      if(NetUserGetInfo( (LPWSTR) ComputerName,
         (LPWSTR) &wszUserName, 2, (LPBYTE *) &ui))
      {
         printf( "Error getting user information.\n" );
         return( FALSE );
      }

      // Convert the Unicode full name to ASCII.

      WideCharToMultiByte( CP_ACP, 0, ui->usri2_full_name,
         -1, dest, 256, NULL, NULL );

      return( TRUE );
   }


Additional reference words: 3.10 3.50
KBCategory: kbnetwork kbnetwork
KBSubcategory: NtwkLmapi


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.