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

Win10 夜間模式/黑色主題一鍵切換:PowerShell 腳本修改登錄檔實現快速開關

編輯:Windows 10 系統介紹

Win10 內建黑色主題 (深色模式) 但缺乏一鍵切換開關,需深入「設定 → 個人化 → 色彩」手動切換。利用 PowerShell 腳本修改登錄檔 AppsUseLightTheme 值,可實現雙擊/右鍵執行即時切換。

PowerShell 腳本內容

  1. 新建文字檔,貼上下列程式碼:
$regkey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
$name = "AppsUseLightTheme"
$exists = Get-ItemProperty -Path "$regkey" -Name "$name" -ErrorAction SilentlyContinue
If (($exists -ne $null) -and ($exists.$name -ne $null)) {
    Remove-ItemProperty -Path $regkey -Name $name
} Else {
    New-ItemProperty -Path $regkey -Name $name -Value 0 -PropertyType DWORD
}
  1. 另存為 ToggleDarkMode.ps1 (編碼選 UTF-8)。
  2. 右鍵檔案 → 「使用 PowerShell 執行」,即可切換深色/淺色模式。再執行一次即切回。

原理說明

  • 登錄檔路徑:HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize
  • 鍵值:AppsUseLightTheme (DWORD)
    1 = 淺色模式 (預設) / 0 = 深色模式 / 鍵值不存在 = 系統預設 (淺色)。
  • 腳本邏輯:偵測鍵值是否存在且為 1 → 存在則刪除 (變深色) → 不存在則建立值 0 (深色) → 實際上為「切換」邏輯。

生效方式:重啟 Explorer.exe

修改登錄檔後必須重啟 explorer.exe 介面才會更新:

  • 工作管理員 → 找到「Windows 檔案總管」→ 右鍵「重新啟動」。
  • 或腳本末尾加入:Stop-Process -Name explorer -Force; Start-Process explorer
  • 或使用第三方工具 (如軟媒魔方)「快捷指令」一鍵重啟 Explorer。

黑色主題效果圖

已知副作用 (早期版本)

開啟深色模式後,「設定」視窗標題列變黑,導致標題文字、最小化/最大化/關閉按鈕難以辨識。此為早期版本未完善之處,新版 Win10 (1809+) 已修正標題列對比度問題。

進階:建立右鍵選單/捷徑一鍵執行

  1. 桌面右鍵 → 新增 → 捷徑 → 位置輸入:powershell.exe -ExecutionPolicy Bypass -File "C:\Path\To\ToggleDarkMode.ps1"
  2. 命名為「切換深色模式」,更換圖示 (如月亮/太陽圖示)。
  3. 釘選到工作列或開始選單,單點即切換。

小結

PowerShell 腳本切換 AppsUseLightTheme 登錄檔值 + 重啟 Explorer,實現 Win10 深色模式一鍵切換。新版 Win10 (1903+) 已在「設定 → 個人化 → 色彩」提供「選擇模式」下拉選單 (淺色/深色/自訂),原生支援更完善,腳本法適合舊版或追求極速切換用戶。

Copyright © Windows教程網 All Rights Reserved