Нашел пример на delphi, но лазарь ругается на ptgGroups.GroupCount
пишет:
unit1.pas(125,28) Error: Illegal qualifier
unit1.pas(125,28) Hint: may be pointer dereference is missing
unit1.pas(125,28) Fatal: Syntax error, "DO" expected but "identifier GROUPCOUNT" found
помогите адаптировать под lazarus
Вот код:
- Код: Выделить всё
const
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority =
(Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
function IsAdmin: Boolean;
var
x: integer;
bSuccess: BOOL;
hAccessToken: THandle;
ptgGroups: PTokenGroups;
dwInfoBufferSize: DWORD;
psidAdministrators: PSID;
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;