15.04.2011, 09:44
|
|
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
Код:
const
ShutdownNoReboot = 0;
ShutdownReboot = 1;
ShutdownPowerOff = 2;
function NtShutdownSystem(SHUTDOWN_ACTION: DWORD): DWORD; stdcall; external 'ntdll.dll';
function EnableShutdownPrivledges: Boolean;
var
hCurrentProcess: THandle;
hTokenHandle: THandle;
tp: _TOKEN_PRIVILEGES;
PreviousState: _TOKEN_PRIVILEGES;
ReturnLength: Cardinal;
begin
hCurrentProcess:=GetCurrentProcess;
if OpenProcessToken(hCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hTokenHandle) then
begin
if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tp.Privileges[0].Luid) then
begin
tp.PrivilegeCount:=1;
tp.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
if AdjustTokenPrivileges(hTokenHandle, False, tp, SizeOf(_TOKEN_PRIVILEGES), PreviousState, ReturnLength) then
Result:=True
else
Result:=False;
end else Result:=False;
end else Result:=False;
end;
использование:
Код:
EnableShutdownPrivledges;
NtShutdownSystem(ShutdownReboot);
Код:
EnableShutdownPrivledges;
NtShutdownSystem(ShutdownPowerOff);
__________________
Пишу программы за еду.
__________________
|