function CheckTokenMembership(TokenHandle: THandle; SidToCheck: PSID;
var IsMember: BOOL): BOOL;
stdcall;
external advapi32;
function RunAsAdmin : Boolean;
const
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
var
pIdentifierAuthority :TSIDIdentifierAuthority;
pSid :
WinApi.Windows.PSid;
IsMember : BOOL;
begin
pIdentifierAuthority := SECURITY_NT_AUTHORITY;
Result := AllocateAndInitializeSid(pIdentifierAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, pSid);
try
if Result
then
if not CheckTokenMembership(0, pSid, IsMember)
then
Result:= False
else
Result:=IsMember;
finally
FreeSid(pSid);
end;
end;