Форум: "WinAPI";
Текущий архив: 2005.11.20;
Скачать: [xml.tar.bz2];
Внизузнать с какими правами запустили программу Найти похожие ветки
← →
Ландграф Павел © (2005-09-19 12:52) [0]как реализовать сабж? а точнее - надо знать админ либо нет...
← →
BiN © (2005-09-19 13:49) [1]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthz/security/checktokenmembership.asp
BOOL IsUserAdmin(VOID)
/*++
Routine Description: This routine returns TRUE if the caller"s process
is a member of the Administrators local group. Caller is NOT expected
to be impersonating anyone and is expected to be able to open its own
process and process token.
Arguments: None.
Return Value:
TRUE - Caller has Administrators local group.
FALSE - Caller does not have Administrators local group. --
*/
{
BOOL b;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
b = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(b)
{
if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
{
b = FALSE;
}
FreeSid(AdministratorsGroup);
}
return(b);
}
← →
xShadow © (2005-09-19 13:49) [2]
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;
← →
psa247 © (2005-09-21 11:25) [3]Проще всего - запросить привилегии и потом проверить GetLastError
if GetLastError = ERROR_NOT_ALL_ASSIGNED then .....
и соответственно делать выводы
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2005.11.20;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.042 c