Autor Beitrag
gudruhn
Hält's aus hier
Beiträge: 4

Win 2000, Win XP
Delphi 7 prof
BeitragVerfasst: Fr 29.04.05 17:43 
Hallo,
ich hoffe, dass ich es heute in die richtige Sparte geschrieben habe... :-)
Habe folgendes Problem:
Ich möchte eine Offline-Update-CD erstellen und dabei vorab abragen, ob der angemeldete User Administratorrechte besitzt. Kann mir dabei jemand helfen?
MfG
Andi


Moderiert von user profile iconmatze: Topic aus Neue Einträge / Hinweise / etc. verschoben am Sa 30.04.2005 um 09:19
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 29.04.05 18:01 
Guck Dir dazu mal die Function IsAdministrator in cvs.sourceforge.net/...source/OIncProcs.pas an. Dort wird gezeigt, wie das funktioniert. Wo die Funktion für Omorphia her ist, steht über der Funktion.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 01.05.05 23:13 
Oder für die Faulen:
ausblenden volle Höhe Delphi-Quelltext
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:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
function GetAdminSid: PSID;
const
  // bekannte SIDs ... (WinNT.h)
  SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (000005));
  // bekannte RIDs ... (WinNT.h)
  SECURITY_BUILTIN_DOMAIN_RID: DWORD = $00000020;
  DOMAIN_ALIAS_RID_ADMINS: DWORD = $00000220;
begin
  Result := nil;
  AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,
    SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
    000000, Result);
end;

////////////////////////////////////////////////////////////////////////////////
//
//  IsAdmin
//    Autor: Nico Bendlin

function IsAdmin: LongBool; 
var 
  TokenHandle: THandle; 
  ReturnLength: DWORD; 
  TokenInformation: PTokenGroups; 
  AdminSid: PSID; 
  Loop: Integer; 
begin 
  Result := False; 
  TokenHandle := 0
  if OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, TokenHandle) then 
  try 
    ReturnLength := 0
    GetTokenInformation(TokenHandle, TokenGroups, nil0, ReturnLength); 
    TokenInformation := GetMemory(ReturnLength); 
    if Assigned(TokenInformation) then 
    try 
      if GetTokenInformation(TokenHandle, TokenGroups, TokenInformation, 
        ReturnLength, ReturnLength) then 
      begin 
        AdminSid := GetAdminSid; 
        for Loop := 0 to TokenInformation^.GroupCount - 1 do 
        begin 
          if EqualSid(TokenInformation^.Groups[Loop].Sid, AdminSid) then 
          begin 
            Result := True; 
            Break; 
          end
        end
        FreeSid(AdminSid); 
      end
    finally 
      FreeMemory(TokenInformation); 
    end
  finally 
    CloseHandle(TokenHandle); 
  end
end;
gudruhn Threadstarter
Hält's aus hier
Beiträge: 4

Win 2000, Win XP
Delphi 7 prof
BeitragVerfasst: Mo 02.05.05 09:16 
Titel: Guten Morgen!
Herzlichen Dank! Werd das dann gleich mal ausprobieren....

MfG

Andi