正道沧桑

正道沧桑

Don't lost yourself.

Switching between dark/light mode

🎨 One-Click Switch for Windows 10 Dark/Light Mode#

Say goodbye to complicated settings menus and easily switch system themes with a simple batch file.

Features#

  • One-Click Switch: Double-click to intelligently switch between dark/light mode.
  • Automatic Detection: Automatically detects the current theme status.
  • Immediate Effect: Changes are applied instantly without needing to restart the system.
  • Safe and Harmless: Only modifies registry theme settings without affecting system stability.

Complete Code#

Save the following code as ThemeSwitcher.bat:

@echo off
setlocal enabledelayedexpansion

echo Checking current theme mode...

:: Read current app theme setting (0=Dark, 1=Light)
for /f "skip=2 tokens=3" %%A in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "AppsUseLightTheme" 2^>nul') do (
    set CurrentTheme=%%A
)

:: If failed to read, default to light mode (1)
if not defined CurrentTheme (
    echo Theme setting not found, defaulting to light mode.
    set CurrentTheme=1
)

:: Determine and switch theme
if "!CurrentTheme!"=="0x0" (
    echo Switching from Dark to Light mode...
    set NewAppTheme=1
    set NewSysTheme=1
    set Message=Switched to Light Mode ✅
) else (
    echo Switching from Light to Dark mode...
    set NewAppTheme=0
    set NewSysTheme=0
    set Message=Switched to Dark Mode 🌙
)

:: Write new registry values
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "AppsUseLightTheme" /t REG_DWORD /d !NewAppTheme! /f >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" /v "SystemUsesLightTheme" /t REG_DWORD /d !NewSysTheme! /f >nul

:: Prompt user
echo.
echo !Message!
echo.
echo Note: Changes may take a few seconds to apply, some apps may need restart.
timeout /t 2 /nobreak >nul

How It Works#

The script switches themes by modifying the following registry keys:

  • AppsUseLightTheme: Controls the application theme.
  • SystemUsesLightTheme: Controls the system interface theme.
ValueTheme Mode
0Dark Mode
1Light Mode

Frequently Asked Questions#

Q: The theme did not change immediately after running the script?
A: This is normal; the system needs a few seconds to refresh the theme settings. You can try pressing Win + D to show the desktop and then return.

Q: Some applications did not switch themes?
A: Some applications may require a restart to apply the new theme settings.

Q: The script does not run?
A: Please ensure you run it as an administrator or adjust your system UAC settings.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.