📄 uautoboot0800.pas
字号:
unit uAutoBoot0800;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls;
type
TAutoBoot0800 = class(TService)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
procedure WriteLogFile;
{ Private declarations }
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
AutoBoot0800: TAutoBoot0800;
implementation
{$R *.DFM}
function Shutdown(Force: boolean; ActionType: integer ):boolean;
var
u, hToken, hProcess: THandle;
tp, prev_tp: TTokenPrivileges;
Len, Flags: DWORD;
begin
Result := False;
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
hProcess := GetCurrentProcess;
// hProcess := OpenProcess(PROCESS_ALL_ACCESS, False, GetCurrentProcessID);
try
if not OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,hToken) then
Exit;
finally
CloseHandle(hProcess);
end;
try
if not LookupPrivilegeValue('', 'SeShutdownPrivilege', tp.Privileges[0].Luid) then Exit;
tp.PrivilegeCount := 1;
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
if not AdjustTokenPrivileges(hToken, False, tp, SizeOf(prev_tp),prev_tp, Len) then
Exit;
finally
CloseHandle(hToken);
end;
end;
if Force then Flags := EWX_FORCE else Flags := 0;
case ActionType of
0: Result := ExitWindowsEx(Flags or EWX_POWEROFF, 0);
1: Result := ExitWindowsEx(Flags or EWX_SHUTDOWN, 0);
2: Result := ExitWindowsEx(Flags or EWX_REBOOT, 0);
3: Result := ExitWindowsEx(Flags or EWX_LOGOFF, 0);
end;
end;
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
AutoBoot0800.Controller(CtrlCode);
end;
function TAutoBoot0800.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TAutoBoot0800.Timer1Timer(Sender: TObject);
var TmpStr: String;
begin
TmpStr:=FormatDateTime('hhmm',Now);
if TmpStr='0800' then
begin
Timer1.Enabled:=False;
//
// Reboot the system
//
WriteLogFile;
ShutDown(True,2);
end;
end;
procedure TAutoBoot0800.WriteLogFile;
var OutFile: TextFile;
begin
AssignFile(OutFile,'c:\AutoBoot.log');
Rewrite(OutFile);
Writeln(OutFile,'Last auto boot at ' + FormatDateTime('yyyy/mm/dd hh:mm:dd',Now));
CloseFile(OutFile);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -