const <br>SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));<br>SECURITY_BUILTIN_DOMAIN_RID = $00000020;<br>DOMAIN_ALIAS_RID_ADMINS = $00000220;<br>function IsAdmin: Boolean;<br>var<br> hAccessToken: THandle;<br> ptgGroups: PTokenGroups;<br> dwInfoBufferSize: DWORD;<br> psidAdministrators: PSID;<br> x: Integer;<br> bSuccess: BOOL;<br>begin<br> Result := False;<br> bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,<br> hAccessToken);<br> if not bSuccess then<br> begin<br> if GetLastError = ERROR_NO_TOKEN then<br> bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,<br> hAccessToken);<br> end; <br> if bSuccess then<br> begin<br> GetMem(ptgGroups, 1024);<br> bSuccess := GetTokenInformation(hAccessToken, TokenGroups,<br> ptgGroups, 1024, dwInfoBufferSize);<br> CloseHandle(hAccessToken);<br> if bSuccess then <br> begin<br> AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,<br> SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,<br> 0, 0, 0, 0, 0, 0, psidAdministrators);<br> {$R-}<br> for x := 0 to ptgGroups.GroupCount - 1 do<br> if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then<br> begin<br> Result := True;<br> Break;<br> end;<br> {$R+}<br> FreeSid(psidAdministrators);<br> end;<br> FreeMem(ptgGroups);<br> end;<br>end;