Registriert seit: 20. Nov 2004
Ort: Berlin
16 Beiträge
Delphi 7 Professional
|
Gruppennamen ermitteln
20. Aug 2006, 01:08
Hallo,
ich möchte unter NT Systemen die Namen der Standardbenutzergruppen ermitteln.
Dazu verwende ich folgende Funktion:
Delphi-Quellcode:
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;
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);
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(nil, Sid,Name, NameSize, DomainName, DomainNameSize, sidType);
if APISuccess then begin
if Assigned(sid) then FreeSid(sid)
end else begin
exit
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(nil, Sid, Name, NameSize, DomainName, DomainNameSize, sidType);
if APISuccess then begin
if Assigned(sid) then FreeSid(sid)
end else begin
exit
end;
End;
End;
result := Name;
end;
Die Funktion LookupAccountSid(nil, Sid, Name, NameSize, DomainName, DomainNameSize, sidType);
gibt allerdings immer ein 'false' wieder.
Wo ist mein Denkfehler.
Danke schonmal im voraus.
Ingo
|