Форум: "WinAPI";
Текущий архив: 2008.01.20;
Скачать: [xml.tar.bz2];
ВнизКак выключить компьютер под xp Найти похожие ветки
← →
Alexey SVD (2007-06-19 16:05) [0]Всем привет! Как выключить компьютер под xp? Финкция ExitWindowsEx вырубает только не NT системы. Есть какие нибудь варианты?
← →
SLoW.AlfaMoon.Com (2007-06-19 17:06) [1]NtShutdownSystem + соответствующая привилегия SE_SHUTDOWN_SYSTEM, емнип
← →
tesseract © (2007-06-19 17:37) [2]Вырубает, вырубает. Посмотри - может у тебя привилегий не хватает.
← →
Anatoly Podgoretsky © (2007-06-19 19:25) [3]> Alexey SVD (19.06.2007 16:05:00) [0]
Вырубает все, думаю и Висту вырубает, но как минимум до Windows 2003 работает, но нужны права.
← →
Инс (2007-06-21 15:57) [4]А врубать привилегию, можно примерно так:
unit ExSecurity;
interface
uses Windows, SysUtils;
type
EPrivilegeException = class(Exception);
const
// Privileges names
SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege";
SE_AUDIT_NAME = "SeAuditPrivilege";
SE_BACKUP_NAME = "SeBackupPrivilege";
SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege";
SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege";
SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege";
SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege";
SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege";
SE_DEBUG_NAME = "SeDebugPrivilege";
SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege";
SE_IMPERSONATE_NAME = "SeImpersonatePrivilege";
SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege";
SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege";
SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege";
SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege";
SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege";
SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege";
SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege";
SE_RESTORE_NAME = "SeRestorePrivilege";
SE_SECURITY_NAME = "SeSecurityPrivilege";
SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege";
SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironment";
SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege";
SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege";
SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege";
SE_TCB_NAME = "SeTcbPrivilege";
SE_UNDOCK_NAME = "SeUndockPrivilege";
SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege";
// Privileges functions
function EnablePrivilegeEx(Process: THandle; Name: String; Enable: Boolean): Boolean;
function EnablePrivilege(Name: String; Enable: Boolean): Boolean;
function IsPrivilegeEx(Process, Thread: THandle; Name: String): Boolean;
function IsPrivilege(Name: String): Boolean;
implementation
procedure PrivilegeException;
begin
raise EPrivilegeException.Create(SysErrorMessage(GetLastError));
end;
function EnablePrivilegeEx(Process: THandle; Name: String; Enable: Boolean): Boolean;
var
LUID: TLargeInteger;
Token: THandle;
Privileges: TOKEN_PRIVILEGES;
ReturnLength: Cardinal;
begin
Result:=false;
if LookupPrivilegeValue(nil,PChar(Name),LUID) then begin
if OpenProcessToken(Process,TOKEN_QUERY or TOKEN_ADJUST_PRIVILEGES,Token) then begin
Privileges.PrivilegeCount:=1;
Privileges.Privileges[0].Luid:=LUID;
if Enable then
Privileges.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED
else
Privileges.Privileges[0].Attributes:=0;
AdjustTokenPrivileges(Token,false,Privileges,SizeOf(TOKEN_PRIVILEGES),Privileges ,ReturnLength);
if GetLastError = ERROR_SUCCESS then Result:=true;
CloseHandle(Token);
end
else begin
PrivilegeException;
end;
end
else begin
PrivilegeException;
end;
end;
function EnablePrivilege(Name: String; Enable: Boolean): Boolean;
begin
Result:=EnablePrivilegeEx(GetCurrentProcess,Name,Enable);
end;
function IsPrivilegeEx(Process, Thread: THandle; Name: String): Boolean;
var
LUID: TLargeInteger;
Token: THandle;
TokenInformation: Pointer;
Size, i: Cardinal;
begin
Result:=false;
if LookupPrivilegeValue(nil,PChar(Name),LUID) then begin
Token:=0;
try
if not OpenThreadToken(Thread,TOKEN_QUERY,false,Token) then
if GetLastError = ERROR_NO_TOKEN then
if not OpenProcessToken(Process,TOKEN_QUERY,Token) then
PrivilegeException;
if not GetTokenInformation(Token,TokenPrivileges,nil,0,Size) then
if GetLastError <> ERROR_INSUFFICIENT_BUFFER then
PrivilegeException;
GetMem(TokenInformation,Size);
try
if not GetTokenInformation(Token,TokenPrivileges,TokenInformation,Size,Size) then
PrivilegeException;
with PTokenPrivileges(TokenInformation)^ do begin
for i:=0 to PrivilegeCount - 1 do begin
if Privileges[i].Luid = LUID then begin
Result:=true;
Break;
end;
end;
end;
finally
FreeMem(TokenInformation,Size);
end;
finally
if Token<>0 then CloseHandle(Token);
end;
end
else begin
PrivilegeException;
end;
end;
function IsPrivilege(Name: String): Boolean;
begin
Result:=IsPrivilegeEx(GetCurrentProcess,GetCurrentThread,Name);
end;
end.
А использовать так:uses ExSecurity;
...
EnablePrivilege(SE_SHUTDOWN_SYSTEM,true);
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2008.01.20;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.044 c