Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Win7 使用 JS 腳本建立一鍵關機捷徑與熱鍵技巧

編輯:Windows 7 系統介紹

除了開始功能表關機、電源鍵、Alt+F4,Win7 可透過 JScript 腳本建立自訂關機捷徑並指派熱鍵,適合喜歡鍵盤操作的進階用戶。

建立關機腳本捷徑

  1. Win+R → notepad 開啟記事本。
  2. 輸入以下程式碼:
    (new ActiveXObject("Shell.Application")).ShutdownWindows();
  3. 另存為:檔案類型選「所有檔案」,檔名 Shutdown.js,存放於桌面或固定資料夾 (如 D:\Scripts\Shutdown.js)。

記事本輸入JS程式碼

另存為Shutdown.js

建立捷徑並指派熱鍵

  1. 在 Shutdown.js 上右鍵 → 「建立捷徑」 (桌面會出現「Shutdown - 速鍵」)。
  2. 右鍵該捷徑 → 「內容」 → 「捷徑」頁籤。
  3. 在「速鍵」欄位按下想指派的組合鍵 (如 Ctrl+Alt+End、Ctrl+Shift+Q 等未被佔用組合) → 確定。

進階變體:直接關機/重開機/登出腳本

若想跳過「關閉 Windows」對話框直接執行動作,可改用 WSH Shell Run 方法呼叫 shutdown.exe:

' 立即關機
CreateObject("WScript.Shell").Run "shutdown.exe -s -t 0 -f", 0, False

' 立即重開機
CreateObject("WScript.Shell").Run "shutdown.exe -r -t 0 -f", 0, False

' 登出
CreateObject("WScript.Shell").Run "shutdown.exe -l", 0, False

存為 ForceShutdown.js 等,同樣可建立捷徑指派熱鍵。

注意

  • ShutdownWindows() 會呼叫系統標準關機對話框 (含關機/重開機/睡眠選項),較安全。
  • shutdown.exe -f 會強制關閉應用程式,可能造成未儲存資料遺失,請謹慎使用。
  • 此技巧同樣適用於 Win8/10/11。
Copyright © Windows教程網 All Rights Reserved