Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6333433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:27:41+00:00 2026-05-24T18:27:41+00:00

DelphiXe, Win7x64 How to define, that the user started the program starts it on

  • 0

DelphiXe, Win7x64

How to define, that the user started the program starts it on behalf of system record of the Administrator of system (domain or local). The rights I define so:

Function IsUserAdmin:Bool;
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 := 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 EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then 
        begin 
          Result := True;
          Break;
        end;
      {$R+}
      FreeSid(psidAdministrators);
    end;
    FreeMem(ptgGroups);
  end;
end;

But it only defines an accessory of the user to group of administrators. How to define, what exactly from under the accounting record “Administrator” goes start (taking into account what the record name can be changed (the account is renamed, example “Admin”)?

P.S. It is all to that if the user starting the application is in group administrator at inclusion Windows UAC at it start on behalf of the Administrator will be all the same requested.

So it is necessary for me:

  1. To learn, that the user which starts the program is in group of
    managers (local or domain) is as works
  2. Start is made on behalf of the system accounting record the “Administrator” (can and renamed), instead of the created new user with the rights of the administrator

[UPDATE]

Once again, in another way. We will admit, in system there are some accounts: Administrator (a system account of the administrator by default), User1 (consists in group “Administrators”, the new created account), User2 (consists in group “Users”, the new created account). For any reasons, system account “Administrator” is renamed in “Admin” (or into any other name). There is my application. It is started by different users. As to me to establish, that the user who starts my application, is the administrator of system (Admin). Because for Windows UAC the rights for start from User1 and Admin will differ – also question UAC will appear only if the application starts User1, and if Admin – message UAC will not appear. Here a question: how to define, what the user who has started the application = Admin (old name Administrator), in other words the user and is the administrator of system?

Need:

Function GetCurrentUserName:string;
begin
... detect current user name
end;

Function isCurrentUserisAdministratorPC:bool; 
begin
// ??? Result:=isUserPCAdmin(GetCurrentUserName);
end;

// uses

User1 start program: isCurrentUserisAdministratorPC return False;

User2 start program: isCurrentUserisAdministratorPC return False;

Admin start program: isCurrentUserisAdministratorPC return TRUE; //!!!

rename account Admin to Test123.

Test123 start program: isCurrentUserisAdministratorPC return TRUE; //!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:27:42+00:00Added an answer on May 24, 2026 at 6:27 pm

    That code checks if the user is a member of the Administrators group. Someone can be a member of the Administrators group, but not have any administrator privelages.

    You want to know if the user actually has administrator privelages. i answered this already here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Win7x64, DelphiXe. Has written the program, which registers the control panel applet (as here
I need a version of PBears thtmlviewer that will work in DelphiXE. I found
I see from this discussion , and the Nick Hodges blog , that the
I need to use a Delphi component to encrypt a file that can then
I have a client/server application written in delphiXe2 using Indy TIdTCPServer and TIdTCPClient that
I had this constants in a Delphi 7 program. They are not compiling under
Any advice or gotchas that I should be aware of. I know to install
We're using Delphi2005 with Delphi2007 patches, also experimenting with DelphiXE SOAP libraries. But I've
For Delphi 2007, the IDE root directory can be found in the system registry
In Delphi XE, I'm trying to use GetForegroundWindow to detect the window that was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.