📄 关机.txt
字号:
unit shutdown;
interface
uses windows;
procedure Reboot;
procedure ShutDownit;
implementation
function IsWin9x: Boolean;
var
OsInfo: TOSVERSIONINFO;
begin
OsInfo.dwOSVersionInfoSize := sizeof(TOSVERSIONINFO);
GetVersionEx(OsInfo);
Result := (OsInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS);
end;
function SetShutdownPrivilege(Enable: Boolean): Boolean;
var
PrevPrivileges: TTokenPrivileges;
Privileges: TTokenPrivileges;
Token: THandle;
dwRetLen: DWord;
begin
Result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token);
Privileges.PrivilegeCount := 1;
if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', Privileges.Privileges[0].LUID) then
begin
if Enable then
Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
Privileges.Privileges[0].Attributes := 0;
dwRetLen := 0;
Result := AdjustTokenPrivileges(Token, False, Privileges, SizeOf(PrevPrivileges), PrevPrivileges, dwRetLen);
end;
CloseHandle(Token);
end;
procedure Reboot;
begin
//Application.Terminate;
if IsWin9x then
ExitWindowsEx(EWX_FORCE or EWX_REBOOT, 0)
else
begin
SetShutdownPrivilege(True);
ExitWindowsEx(EWX_FORCE or EWX_REBOOT, 0);
SetShutdownPrivilege(False);
end;
end;
procedure ShutDownit;
begin
//Application.Terminate;
if IsWin9x then
ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0)
else
begin
SetShutdownPrivilege(True);
ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0);
SetShutdownPrivilege(False);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -