Getting the name of a user or group in Windows by their SID (security identifier) according to the localization of the operating system.
1 2 3 4 5 6 7 |
var sid, name: string; begin sid:= 'S-1-5-32-544'; name:= SIDToName(sid); ShowMessage(name); end; |
Options
sid - SID of group or user
SIDs of some major user groups:
- S-1-1-0 All
- S-1-5-32-544 Administrators
- S-1-5-32-545 Users
- S-1-5-11 Verified
Result
User or group name on success and an empty string on failure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function SIDToName (StrSID: string): string; var SID : PSID; Buffer : PAnsiChar; NameLen, TempLen : Cardinal; err : Boolean; SIDType : Dword; Name : string; begin SID := nil; Name:= ''; err := ConvertStringSIDToSID(PWideChar(StrSID), SID); if err then begin NameLen := 0; TempLen := 0; LookupAccountSidA(nil, SID, nil, NameLen, nil, TempLen, SIDType); GetMem(Buffer, NameLen); try err := LookupAccountSidA(nil, SID, Buffer, NameLen, nil, TempLen, SIDType); if err then SetString(Name, Buffer, Namelen); finally FreeMem(Buffer); end; end; if Assigned(SID) then LocalFree(Cardinal(SID)); result := Name; end; |
1 thought on “Get the name of a user or group by SID”
Comments are closed.