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 code | Description |
|---|---|
|
The lpNameBuffer buffer is too small. The lpnSize parameter contains the number of bytes required to receive the name. |
|
The domain controller is not available to perform the lookup |
|
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 |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names |
GetUserNameExW (Unicode) and GetUserNameExA (ANSI) |
See also