I am looking for working (obviously) Delphi 7 code so I can check whether my program is started with administrator rights.
Thanks in advance
[--- IMPORTANT UPDATE ---]
Having reviewed the code in the answers so far, I realise that my question maybe is not so clear, or at least is not complete:
I want to know whether my Delphi 7 program is started with the 'Run as admin' check box set.
In other words: I want to know whether it is possible for my Delphi 7 program to create/update files in the c:\Program Files... folders.
Just checking if you have administrator rights is not enough for this.
The Windows API (used) to have a helper function (IsUserAnAdmin) to tell if you are running with administrative privileges.
The Shell32 wrapper function is deprecated; which is fine because it was just a wrapper around other code, which you can still call yourself:
In other words: This function gives you the answer you want: Can the user update Program Files.
You need to be weary of code that check if you're a member of the Administrator's group. You can be part of the Administrator's group, but not have any administrative privileges. You can also have administrative privileges, but not be part of the Administrator's group.
Project JEDI's JEDI Code Library has an IsAdministrator function in the JclSecurity unit that will tell you. It still works in Delphi 7.
This code works under D7..XE inc.
Jwscl (The Jedi Windows Security Library) has a function for this: JwCheckAdministratorAccess.
usage is very simple:
This function works also in Windows Vista and later if UAC is enabled. If the current process is not elevated the return value is false even if the token contains the administrators group (which is disabled then). This function detects a group membership in the administrator group which means that the user don't need to be in the administrators group directly instead a group can be a member of the administrators group.
I tested this code with Delphi 7, on Windows XP, 7 and 8 (admin and limited accounts):