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: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
| function TokenToUserSidString(Token: THandle): string; const SECURITY_NT_AUTHORITY = 5; type PSID = ^TSID; TSID = packed record Revision: Byte; SubAuthorityCount: Byte; IdentifierAuthority: TSIDIdentifierAuthority; SubAuthority: array [Byte] of DWORD; end; PTokenUser = ^TTokenUser; TTokenUser = record User: TSIDAndAttributes; end; var User: PTokenUser; Size: DWORD; Loop: Byte; begin Result := ''; Size := 4096; GetMem(User, Size); try FillChar(User^, Size, 0); if GetTokenInformation(Token, TokenUser, User, Size, Size) then with PSID(User^.User.Sid)^ do begin Result := 'S-' + IntToStr(Revision) + '-' + IntToStr(IdentifierAuthority.Value[SECURITY_NT_AUTHORITY]); for Loop := 0 to SubAuthorityCount - 1 do Result := Result + '-' + IntToStr(SubAuthority[Loop]); end; finally FreeMem(User); end; end; |