function GetGroupName(index:integer):string;
const DOMAIN_ALIAS_RID_ADMINS = $00000220;
DOMAIN_ALIAS_RID_GUESTS = $00000222;
DOMAIN_ALIAS_RID_USERS = $00000221;
SECURITY_WORLD_RID = $00000000;
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
var Error, rid:integer;
NameSize, DomainNameSize:DWORD;
sia:SID_IDENTIFIER_AUTHORITY;
TargetComputer,DomainName, Name:pchar;
sid:psid;
sidType: SID_NAME_USE;
APISuccess : boolean;
begin
Case index of
0 : Rid := DOMAIN_ALIAS_RID_ADMINS;
1 : Rid := DOMAIN_ALIAS_RID_GUESTS;
2 : Rid := DOMAIN_ALIAS_RID_USERS;
3 : Rid := 0;
end;
TargetComputer := '';
NameSize := 1024;
DomainNameSize := 1024;
GetMem(Name, 1024);
GetMem(DomainName, 1024);
sia := SECURITY_NT_AUTHORITY;
If Rid = 0 then
begin
sia.Value[5] := 1;
If AllocateAndInitializeSid(sia, 1, SECURITY_WORLD_RID , Rid, 0, 0, 0, 0, 0, 0, Sid) then
begin
APISuccess := LookupAccountSid(0, Sid,Name, NameSize, DomainName, DomainNameSize, sidType);
if APISuccess then begin
if Assigned(sid) then FreeSid(sid)
end else begin
name := '';
end;
End;
end else begin
sia.Value[5] := 5 ;
If AllocateAndInitializeSid(sia, 2, SECURITY_BUILTIN_DOMAIN_RID, Rid, 0, 0, 0, 0, 0, 0, Sid) then
begin
APISuccess := LookupAccountSid(0, Sid, Name, NameSize, DomainName, DomainNameSize, sidType);
if APISuccess then begin
if Assigned(sid) then FreeSid(sid)
end else begin
name := '';
end;
End;
End;
result := Name;
end;