program shutdown; {$APPTYPE CONSOLE} uses windows; var ComputerName: array[0..MAX_COMPUTERNAME_LENGTH + 1] of char; sComputerName: string; lpSize: DWORD; function TimedShutDown(Computer: string; Msg: string; //获取关机特权 Time: Word; Force: Boolean; Reboot: Boolean): Boolean; var rl: Cardinal; hToken: Cardinal; tkp: TOKEN_PRIVILEGES; begin OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken); if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; tkp.PrivilegeCount := 1; AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl); end; Result := InitiateSystemShutdown(PChar(Computer), PChar(Msg), Time, Force, Reboot) end; begin { TODO -oUser -cConsole Main : Insert code here } //调用 writeln(ComputerName); readln; lpSize := MAX_COMPUTERNAME_LENGTH + 1; if GetComputerName(@ComputerName, lpSize) then begin sComputerName := ComputerName; end else begin sComputerName := ''; end; TimedShutDown(sComputerName, '', 0, true, true); end.