Hola,
Hace tiempo que ocupo el siguiente código, a ver si te sirve a ti también:
Código Delphi
[-]
uses
Windows;
const
SECURITY_NT_AUTHORITY : TSIDIdentifierAuthority = ( Value : ( 0, 0, 0, 0, 0, 5 ) );
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
DOMAIN_ALIAS_RID_USERS = $00000221;
DOMAIN_ALIAS_RID_GUESTS = $00000222;
DOMAIN_ALIAS_RID_POWER_USERS = $00000223;
function CheckTokenMembership(TokenHandle: THandle; SidToCheck: PSID; var IsMember: BOOL): BOOL; stdcall; external advapi32;
function IsUserAdmin : Boolean;
var
b: BOOL;
AdministratorsGroup: PSID;
begin
b := AllocateAndInitializeSid(
SECURITY_NT_AUTHORITY,
2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, AdministratorsGroup);
if (b) then
begin
if not CheckTokenMembership(0, AdministratorsGroup, b) then
b := False;
FreeSid(AdministratorsGroup);
end;
Result := b;
end;
Ejemplo de uso:
Código Delphi
[-]
if IsUserAdmin() then
begin
end;
En el
hilo de Stackoverflow donde lo encontré puedes acaso obtener más información.