Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GetUserNameEx function

Retrieves the name of the user or other security principal associated with the calling thread. You can specify the format of the returned name.

If the thread is impersonating a client, GetUserNameEx returns the name of the client.

Syntax


BOOLEAN WINAPI GetUserNameEx(
  _In_     EXTENDED_NAME_FORMAT NameFormat,
  _Out_    LPTSTR lpNameBuffer,
  _Inout_  PULONG lpnSize
);

Parameters

NameFormat [in]

The format of the name. This parameter is a value from the EXTENDED_NAME_FORMAT enumeration type. It cannot be NameUnknown. If the user account is not in a domain, only NameSamCompatible is supported.

lpNameBuffer [out]

A pointer to a buffer that receives the name in the specified format. The buffer must include space for the terminating null character.

lpnSize [in, out]

On input, this variable specifies the size of the lpNameBuffer buffer, in TCHARs. If the function is successful, the variable receives the number of TCHARs copied to the buffer, not including the terminating null character.

If lpNameBuffer is too small, the function fails and GetLastError returns ERROR_MORE_DATA. This parameter receives the required buffer size, in Unicode characters (whether or not Unicode is being used), including the terminating null character.

Return value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError. Possible values include the following.

Return codeDescription
ERROR_MORE_DATA

The lpNameBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name.

ERROR_NO_SUCH_DOMAIN

The domain controller is not available to perform the lookup

ERROR_NONE_MAPPED

The user name is not available in the specified format.

 

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Secext.h (include Security.h)

Library

Secur32.lib

DLL

Secur32.dll

Unicode and ANSI names

GetUserNameExW (Unicode) and GetUserNameExA (ANSI)

See also

EXTENDED_NAME_FORMAT
LookupAccountName
System Information Functions

 

 

Community Additions

Show:
© 2014 Microsoft