You need to discover information about a user or group, and you have a username or user ID or a group name or ID.
Windows identifies users and groups using security identifiers (SIDs), which are unique, variably sized values assigned by an authority such as the local machine or a Windows NT server domain. Functions and data structures typically represent users and groups using SIDs, rather than using names.
The Win32 API provides numerous functions for manipulating SIDs, but
of particular interest to us in this recipe are the functions
LookupAccountName( ) and
LookupAccountSid( ), which are used to map between
names and SIDs.
The Win32 API function
is used to find the SID that corresponds to a
name. You can use it to obtain information about a name on either the
local system or a remote system. While it might seem that mapping a
name to a SID is a simple operation,
) actually requires a large number of arguments to allow it
to complete its work.
LookupAccountName( ) has the following signature:
BOOL LookupAccountName(LPCTSTR lpSystemName, LPCTSTR lpAccountName, PSID Sid, LPDWORD cbSid, LPTSTR ReferencedDomainName, LPDWORD cbReferencedDomainName, PSID_NAME_USE peUse);
This function has the following arguments:
String representing the name of the remote system on which to look up
the name. If you specify this argument as
NULL, the lookup will be done on ...