Results 1 to 1 of 1
  1. #1
    jaxBR
    jaxBR is offline
    New member jaxBR's Avatar
    Join Date
    2012 Jan
    Posts
    37
    Thanks
    33
    Thanked 35 Times in 15 Posts
    Rep Power
    0

    checking administrator user

    Code:
    function IsAdmin:Boolean;
    const
      SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0,0,0,0,0,5));
      SECURITY_BUILTIN_DOMAIN_RID = $00000020;
      DOMAIN_ALIAS_RID_ADMINS     = $00000220;
    var
      IsUserAnAdmin: function(): BOOL; stdcall;
      hAccessToken: THandle;
      ptgGroups: PTokenGroups;
      dwInfoBufferSize: DWORD;
      psidAdministrators: PSID;
      xi: Integer;
      bSuccess: BOOL;
      hMod: Thandle;
    begin
     Result:=True;
     if IsWin9x then Exit;
     Result:=False;
     hAccessToken:=0;
     hMod:=GetModuleHandle('shell32.dll');
     if hMod=0 then hMod:=LoadLibrary('shell32.dll');
     IsUserAnAdmin:=GetProcAddress(hMod,'IsUserAnAdmin');
     if not Assigned(IsUserAnAdmin) then begin
      bSuccess:=OpenThreadToken(GetCurrentThread,TOKEN_QUERY,True,hAccessToken);
      if not bSuccess then if GetLastError=ERROR_NO_TOKEN then
       bSuccess:=OpenProcessToken(GetCurrentProcess,TOKEN_QUERY,hAccessToken);
      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);
          if ptgGroups.GroupCount>0 then
            for xi:=0 to ptgGroups.GroupCount-1 do
             if EqualSid(psidAdministrators,ptgGroups.Groups[xi].Sid) then begin
              Result:=True;
              Break;
             end;
          FreeSid(psidAdministrators);
        end;
        FreeMem(ptgGroups);
      end;
     end
     else Result:=IsUserAnAdmin();
    end;
    Example of use in formCreate...FormShow or timer

    Code:
          if IsAdmin then {ADM} else
    Label.Caption := 'Execute como Administrador';

Similar Threads

  1. [Tool] User Manager for BoI
    By ranaza21 in forum Battle of the Immortals
    Replies: 1
    Last Post: 2017-01-22, 11:11 PM
  2. [Tutorial] checking debugger
    By jaxBR in forum Delphi
    Replies: 0
    Last Post: 2013-11-08, 09:32 PM
  3. Hello all user
    By xsoftz in forum Introduction / Say 'Hello'
    Replies: 0
    Last Post: 2012-09-23, 02:12 AM
  4. Hello all user
    By witawat in forum Introduction / Say 'Hello'
    Replies: 0
    Last Post: 2012-09-22, 03:10 AM
  5. [Help] NPC User Lan House
    By LKMaster in forum Aika Online
    Replies: 5
    Last Post: 2012-03-22, 12:21 AM
Visitors found this page by searching for:
Nobody landed on this page from a search engine, yet!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •