(Gast)
n/a Beiträge
|
Re: Autostart ohne Adminrechte
5. Dez 2006, 18:11
So hab mal zwei functionen geschrieben aber seht selbs:
(bitte nicht aufrechtschreibfehler achten bin ersz 14 )
Delphi-Quellcode:
function IstAdmin: Boolean;
const
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:=False;
ptgGroups:=nil;
psidAdministrators:=nil;
try
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);
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 EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then
begin
Result := True;
Break;
end;
{$R+}
end;
end;
finally
if bSuccess then
CloseHandle(hAccessToken);
if Assigned(ptgGroups) then
FreeMem(ptgGroups);
if Assigned(psidAdministrators) then
FreeSid(psidAdministrators);
end;
end;
function CreateAutorunEntry: Boolean;
var
Reg: TRegistry;
AKind: TAutorunKind;
begin
Result:=False;
Reg := TRegistry.create;
try
if IstAdmin = True then
Reg.RootKey := HKEY_LOCAL_MACHINE
else
Reg.Rootkey:= HKEY_CURRENT_USER;
if Reg.RootKey = HKEY_LOCAL_MACHINE then
Akind:=akRun;
if Reg.Rootkey = HKEY_CURRENT_USER then
AKind:=akUserRun;
case AKind of
akRun, akUserRun : Result:=Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True);
end;
Reg.WriteString({Name des eintages},{Dateipfad});
finally
Reg.Free;
end;
end;
|
|
Zitat
|