Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.04.23;
Скачать: CL | DM;

Вниз

Права админа   Найти похожие ветки 

 
V-A-V ©   (2006-02-03 14:14) [0]

Как узнать имеет ли текущий юзер права администратора?


 
Eraser ©   (2006-02-03 14:20) [1]


> V-A-V ©   (03.02.06 14:14)

function IsAdmin: Boolean;
var
 hAccessToken: THandle;
 ptgGroups: PTokenGroups;
 dwInfoBufferSize: DWORD;
 psidAdministrators: PSID;
 x: Integer;
 bSuccess: BOOL;
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;


Начиная с win2K есть ф-я IsUserAnAdmin.


 
Игорь Шевченко ©   (2006-02-03 14:24) [2]

http://www.swissdelphicenter.ch/torry/showcode.php?id=189


 
V-A-V ©   (2006-02-03 15:03) [3]

благодарю, попробую.


 
Dmitrij_K   (2006-02-03 16:21) [4]

Вопрос в тему.
Чем не подходит IsUserAnAdmin из shell32.dll?


 
Eraser ©   (2006-02-03 16:23) [5]


> Dmitrij_K   (03.02.06 16:21) [4]

Тем что на NT системе младше 2K работать не будет.


 
Dmitrij_K   (2006-02-03 16:25) [6]

2 [5]
Спасибо



Страницы: 1 вся ветка

Текущий архив: 2006.04.23;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.047 c
3-1141384511
Валерий
2006-03-03 14:15
2006.04.23
обновление данных


2-1144653791
Gydvin
2006-04-10 11:23
2006.04.23
Control Myrich1 has no parent window


2-1144620145
mfender
2006-04-10 02:02
2006.04.23
Отследить изменение значения поля


4-1138784983
Polevi
2006-02-01 12:09
2006.04.23
wait functions


4-1138915613
den_c
2006-02-03 00:26
2006.04.23
Язык системы.