The Will Will Web

記載著 Will 在網路世界的學習心得與技術分享

Windows 各種排程關機的方法

每天在下班前總會整理一下電腦裡的檔案,或是執行一些比較花時間的程式,例如說刪除 Outlook 中「刪除的郵件」資料夾內的郵件、執行 Windows Desktop Search 的索引、執行 SmartDefrag 重整硬碟、或是下載很大的檔案,這些動作一向費時,而且有些程式在執行的時候電腦慢的跟烏龜一樣幾乎不能用,為了響應「節能減炭」我個人還是傾向於下班後要關機,因此找了一些「排程關機」的方法,介紹如下:

使用內建的 shutdown 指令

Windows 內建的 shutdown 指令在 Windows XP, Vista, Server 都有支援,可以指定參數做「登出」、「關機」、「重新啟動」等動作,除了可以「排定時間關機」外,還可以支援「操作遠端電腦」關機的功能,只要你的電腦有加入 AD 且你具有足夠的權限就可以將遠端的電腦關機,若沒加入 AD 只要遠端電腦跟你的電腦有相同的帳號、密碼也可以進行遠端關機。

在 Windows XP 中的 shutdown 指令可排程超過 1 天的時間,例如你要排程 2 天後關機,可以輸入以下指令:

shutdown -s -t 172800

若你使用的是 Windows Vista

若要中斷關機的排程,可以輸入以下指令:

shutdown -a

詳細的操作說明可以輸入 shutdown /? 查詢:

C:\>shutdown /?
使用方式: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c
 "comment"] [-d up:xx:yy]

        沒有引數                顯示這個訊息 (和 -? 相同)
        -i                      顯示 GUI 介面,必須是第一個選項
        -l                      登出 (不能和 -m 選項一起使用)
        -s                      電腦關機
        -r                      關機並重新啟動電腦
        -a                      中止系統關機
        -m \\\\computername     從遠端進行關機/重新啟動/中止
        -t xx                   將關機等候時間設定成 xx 秒
        -c "comment"            關機註解 (最多 127 個字元)
        -f                      強制關閉執行中的應用程式,不顯示警告
        -d [u][p]:xx:yy         關機原因代碼
                                u 是使用者代碼
                                p 是預先計劃的關機代碼
                                xx 是主要原因代碼 (小於 256 的正整數)
                                yy 是次要原因代碼 (小於 65536 的正整數)

不過,若你使用 Windows Vista 或 Windows Server 系列,內建的 shutdown 可排程的時間最多只支援 600 秒而已!

使用更強的 PsShutdown 工具

使用由 Sysinternals 系列的 PsShutdown 工具可操控的範圍更廣了,除了支援「登出」、「關機」、「重新啟動」等動作外,還支援「待命(Suspend)」或「休眠(Hibernate)」等功能,也一樣能夠透過參數指定不同關機指令的組合。

例如你要將電腦在等下的凌晨 3:00 進入「待命」狀態,可以用以下指令參數:

psshutdown -d -t 03:00

若要取消關機排程,可以用以下指令:

psshutdown -a

若要查詢完整參數說明,可以輸入 psshutdown -? 查詢,不過這指令在「繁體中文」的作業系統中似乎會出現亂碼,我在英文 OS 下的結果如下:

C:\>psshutdown /?

PsShutdown v2.52 - Shutdown, logoff and power manage local and remote systems
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

usage:
psshutdown -s|-r|-h|-d|-k|-a|-l|-o [-f] [-c] [-t [nn|h:m]] [-v nn] [-e [u|p]:xx:
yy] [-m "message"] [-u Username [-p password]] [-n s] [\\computer[,computer[,...
]|@file]
   -a          Abort a shutdown (only possible while countdown is in progress)
   -c          Allow the shutdown to be aborted by the interactive user
   -d          Suspend the computer
   -e          Shutdown reason code (available on Windows XP and higher).
               Specify 'u' for unplanned and 'p' for planned
               shutdown reason codes.
               xx is the major reason code (must be less than 256)
               yy is the minor reason code (must be less than 65536)
   -f          Forces running applications to close
   -h          Hibernate the computer
   -k          Poweroff the computer (reboot if poweroff is not supported)
   -l          Lock the computer
   -m          Message to display to logged on users
   -n          Specifies timeout in seconds connecting to remote computers
   -o          Logoff the console user
   -p          Specifies optional password for user name. If you omit this
               you will be prompted to enter a hidden password.
   -r          Reboot after shutdown
   -s          Shutdown without poweroff
   -t          Specifies countdown in seconds until shutdown (default is 20) or
               the time of shutdown (in 24 hour notation)
   -u          Specifies optional user name for login to remote
               computer.
   -v          Display message for the specified number of seconds before
               the shutdown. If you omit this parameter the shutdown
               notification dialog displays and specifying a value of 0
               omits the dialog.
   computer    Shutdown the computer or computers specified
   @file       Shutdown the computers listed in the file specified


Reasons defined on this computer (U = unplanned, P = planned):
Type   Major   Minor   Title
  U      0       0     Other (Unplanned)
  P      0       0     Other (Planned)
  U      1       1     Hardware: Maintenance (Unplanned)
  P      1       1     Hardware: Maintenance (Planned)
  U      1       2     Hardware: Installation (Unplanned)
  P      1       2     Hardware: Installation (Planned)
  P      2       3     Operating System: Upgrade (Planned)
  U      2       4     Operating System: Reconfiguration (Unplanned)
  P      2       4     Operating System: Reconfiguration (Planned)
  P      2      16     Operating System: Service pack (Planned)
  U      2      17     Operating System: Hot fix (Unplanned)
  P      2      17     Operating System: Hot fix (Planned)
  U      2      18     Operating System: Security fix (Unplanned)
  P      2      18     Operating System: Security fix (Planned)
  U      4       1     Application: Maintenance (Unplanned)
  P      4       1     Application: Maintenance (Planned)
  P      4       2     Application: Installation (Planned)
  U      4       5     Application: Unresponsive
  U      4       6     Application: Unstable
  U      5      19     Security issue
  P      5      19     Security issue
  U      5      20     Loss of network connectivity (Unplanned)
  P      7       0     Legacy API shutdown

相關連結

留言評論