关机.txt
来自「这个是先生供奉」· 文本 代码 · 共 65 行
TXT
65 行
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 + =
减小字号Ctrl + -
显示快捷键?