uses
windows;
const
EWX_LOGOFF = 0; //重新启动计算机并切换到MS-DOS方式
EWX_SHUTDOWN = 1; //关闭计算机 -
EWX_REBOOT = 2; //重新启动计算机 -
EWX_FORCE = 4; //关闭所有程序并以其他用户身份登录
var
hToken: THandle;
tkp: TOKEN_PRIVILEGES;
ReturnLength: DWord;
begin
readln;
if (not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken)) then
begin
exit;
end;
LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
ReturnLength := 0;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0, nil, ReturnLength);
if (GetLastError() <> ERROR_SUCCESS) then
begin
exit;
end;
if (not ExitWindowsEx(EWX_REBOOT, 0)) then //关机
begin
exit;
end;
end.