procedure TForm1.ExitWindowsNT(uFlags: Integer); //Win2000、NT关机过程
var
hToken: THandle;
tkp, tkDumb: TTokenPrivileges;
DumbInt: DWORD;
begin
FillChar(tkp, sizeof(tkp), 0);
if not (OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)) then
Exit;
LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, False, tkp, sizeof(tkDumb), tkDumb, DumbInt);
if GetLastError <> ERROR_SUCCESS then
Exit;
if not ExitWindowsEx(uFlags, 0) then
Exit;
end;
procedure TForm1.dxBarButton10Click(Sender: TObject); //重起计算机
var
VerTest: DWORD;
begin
VerTest := GetVersion;
if (VerTest < $80000000) then
ExitWindowsNT(EWX_REBOOT)
else
ExitWindowsEx(EWX_REBOOT, 0);
end;
使用一个定时器,属性Interval为默认,在Form的OnCreate中使定时器的Enable为True
然后检测时间,到了你规定的时间,执行重起过程。