Registriert seit: 12. Mai 2006
18 Beiträge
|
Re: lokale Benutzerrechte herausfinden
21. Dez 2006, 16:36
Zitat von BBG:
Wieso denn read-only? Das darf doch jeder Benutzer??
Poste doch mal die Procedure...
Hast ja recht, ich meinte es eher symbolisch (war leider nicht erkennbar), ich versuche also einen HKLM Eintrag zu erstellen.
Hier die Proc:
Delphi-Quellcode:
function IsAdmin: boolean;
const
SE_GROUP_MANDATORY = $00000001;
SE_GROUP_ENABLED_BY_DEFAULT = $00000002;
SE_GROUP_ENABLED = $00000004;
SE_GROUP_OWNER = $00000008;
SE_GROUP_USE_FOR_DENY_ONLY = $00000010;
SE_GROUP_LOGON_ID = $C0000000;
SE_GROUP_RESOURCE = $20000000;
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
var
hAccessToken: THandle;
ptgGroups: PTokenGroups;
dwInfoBufferSize: DWORD;
psidAdministrators: PSID;
x: Integer;
bSuccess: BOOL;
begin
Result := False;
bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken);
if not bSuccess then begin
if GetLastError = ERROR_NO_TOKEN then
bSuccess := OpenProcessToken( GetCurrentProcess, TOKEN_QUERY, hAccessToken );
end;
if bSuccess then begin
GetMem(ptgGroups, 1024);
bSuccess := GetTokenInformation(hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize);
CloseHandle(hAccessToken);
if bSuccess then begin
AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, psidAdministrators);
{$R-}
for x := 0 to ptgGroups.GroupCount - 1 do
if ( SE_GROUP_ENABLED =
( ptgGroups.Groups[x].Attributes and SE_GROUP_ENABLED)) and EqualSid(psidAdministrators,
ptgGroups.Groups[x].Sid ) then begin
Result := True;
Break;
end;
{$R+}
FreeSid(psidAdministrators);
end;
FreeMem(ptgGroups);
end;
end;
[edit=Christian Seehase]Delphi-Tags gesetzt. Bitte künftig selber machen. Danke. Mfg, Christian Seehase[/edit]
|
|
Zitat
|