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

C++
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.

If this parameter is greater than 32767, the function fails and GetLastError returns ERROR_MORE_DATA.

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 clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderSecext.h (include Security.h)
LibrarySecur32.lib
DLLSecur32.dll
Unicode and ANSI namesGetUserNameExW (Unicode) and GetUserNameExA (ANSI)

See Also

EXTENDED_NAME_FORMAT
LookupAccountName
System Information Functions

Send comments about this topic to Microsoft

Build date: 11/19/2009

Tags :


Page view tracker