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

Вниз

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

 
T2 ©   (2003-08-02 16:06) [0]

Как узнать, выполнен вход в систему под Администратором или под Пользователем?


 
Zero Ice   (2003-08-02 20:27) [1]

function IsAdmin: Boolean;
const
SECURITY_NT_AUTHORITY : TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
var
hAccessToken : THandle;
ptgGroups : PTokenGroups;
dwInfoBufferSize : DWORD;
psidAdministrators : PSID;
i : Integer;
bSuccess : BOOL;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
begin
Result := True;
Exit;
end;

Result := False;
bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken);
if not bSuccess then
begin
if GetLastError = ERROR_NO_TOKEN then
begin
bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken);
end;
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 i := 0 to ptgGroups.GroupCount-1 do
begin
if EqualSid(psidAdministrators, ptgGroups.Groups[i].Sid) then
begin
Result := True;
Break;
end;
end;
{$R+}
FreeSid(psidAdministrators);
end;
( ptgGroups) function IsAdmin: Boolean;
const
SECURITY_NT_AUTHORITY : TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
var
hAccessToken : THandle;
ptgGroups : PTokenGroups;
dwInfoBufferSize : DWORD;
psidAdministrators : PSID;
i : Integer;
bSuccess : BOOL;
begin
if Win32Platform <> VER_PLATFORM_WIN32_NT then
begin
Result := True;
Exit;
end;

Result := False;
bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken);
if not bSuccess then
begin
if GetLastError = ERROR_NO_TOKEN then
begin
bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken);
end;
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 i := 0 to ptgGroups.GroupCount-1 do
begin
if EqualSid(psidAdministrators, ptgGroups.Groups[i].Sid) then
begin
Result := True;
Break;
end;
end;
{$R+}
FreeSid(psidAdministrators);
end;
FreeMem(ptgGroups);
end;
end;


 
AbrosimovA ©   (2003-08-04 08:22) [2]

Прочитать из реестра значение параметра DefaultUserName
в ветке HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

Это значение всегда показывает имя текущего пользователя в WinNT,Win2k и WinXP.


 
Kesha   (2003-08-05 18:39) [3]

2Zero Ice
Это вроде как определяет только локального админа.
А как определить, я вляется ли пользователь администратором в домене?
Желательно с работающим примером...

PS MSDN перелопатил как смог...


 
Air_demon   (2003-08-06 12:04) [4]

Есть пример на VBScript, но можно и на Delphi.
Используется WMI.

sNode = "." " "." for local computer

Set oSWbemLoc = CreateObject("wbemScripting.SWbemLocator")
Set oWMI = oSWbemLoc.ConnectServer(sNode, "root\cimv2")

Set oLoggedOnUsers = oWMI.ExecQuery _
("Select * from Win32_LoggedOnUser", "WQL", 32)

iUsers = 0
For Each oUser In oLoggedOnUsers
( oUser.Antecedent, 0) Есть пример на VBScript, но можно и на Delphi.
Используется WMI.

sNode = "." " "." for local computer

Set oSWbemLoc = CreateObject("wbemScripting.SWbemLocator")
Set oWMI = oSWbemLoc.ConnectServer(sNode, "root\cimv2")

Set oLoggedOnUsers = oWMI.ExecQuery _
("Select * from Win32_LoggedOnUser", "WQL", 32)

iUsers = 0
For Each oUser In oLoggedOnUsers
Set oAccount = oWMI.Get(oUser.Antecedent, 0)
If oAccount.SIDType = 1 Then
iUsers = iUsers + 1
WScript.Echo "Domain/Machine = " & oAccount.Domain & " " & "Account = " &oAccount.name
End If
Next



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

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

Наверх




Память: 0.48 MB
Время: 0.019 c
1-65434
Дмитрий
2003-10-07 15:13
2003.10.20
Подключить dll для перевода текста


1-65513
Bezpal
2003-10-08 13:00
2003.10.20
Дата


14-65610
Izyum
2003-10-01 10:18
2003.10.20
Разве можно так пить?


1-65499
Alesha aka Pokemon
2003-10-08 12:32
2003.10.20
Ссылки и указатели.


1-65539
sasach
2003-10-08 09:06
2003.10.20
посоветуйте...