Platform SDK: Access Control

LookupAccountName

The LookupAccountName function accepts the name of a system and an account as input. It retrieves a security identifier (SID) for the account and the name of the domain on which the account was found.

BOOL LookupAccountName(
  LPCTSTR lpSystemName,   // system name
  LPCTSTR lpAccountName,  // account name
  PSID Sid,               // security identifier
  LPDWORD cbSid,          // size of security identifier
  LPTSTR DomainName,      // domain name
  LPDWORD cbDomainName,   // size of domain name
  PSID_NAME_USE peUse     // SID-type indicator
);

Parameters

lpSystemName
[in] Pointer to a null-terminated string specifying the system. This string can be the name of a remote computer. If this string is NULL, the account name is looked up on the local system.
lpAccountName
[in] Pointer to a null-terminated string specifying the account name.
Sid
[out] Pointer to a buffer receiving the SID structure that corresponds to the account name pointed to by the lpAccountName parameter. If this parameter is NULL, the function returns the required buffer size.
cbSid
[in/out] Pointer to a variable. On input, this value specifies the size, in bytes, of the Sid buffer. If the function fails because the buffer is too small, this variable receives the required buffer size. If the Sid parameter is NULL, this parameter must be zero.
DomainName
[out] Pointer to a buffer receiving the name of the domain where the account name is found. If this parameter is NULL, the function returns the required buffer size.
cbDomainName
[in/out] Pointer to a variable. On input, this value specifies the size, in TCHARs, of the DomainName buffer. If the function fails because the buffer is too small, this variable receives the required buffer size, including the terminating null character. If the DomainName parameter is NULL, this parameter must be zero.
peUse
[out] Pointer to a SID_NAME_USE enumerated type indicating the type of the account when the function returns.

Return Values

If the function succeeds, the return value is nonzero.

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

Remarks

The LookupAccountName function attempts to find a security identifier for the specified name by first checking a list of well-known SIDs. If the name does not correspond to a well-known SID, the function checks built-in and administratively defined local accounts. Next, the function checks the primary domain. If the name is not found there, trusted domains are checked.

Windows 2000: In addition to lookup up local accounts, local domain accounts, and explicitly trusted domain accounts, LookupAccountName can look up the name for any account in any domain in the Windows 2000 forest.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Access Control Overview, Access Control Functions, EqualPrefixSid, GetUserName, LookupAccountSid