How do I change the current Windows theme programmatically?

前端 未结 12 1964
轻奢々
轻奢々 2020-12-04 11:12

I want to allow my users to toggle the current user theme between Aero and Windows Classic(1). Is there a way that I can do this programatically?

I don\'t want to po

12条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 11:55

    I have been experimenting about changing the windows theme via command line and I learned that by executing the theme file it is being applied by the Windows 10 as well. So in your batch file, you could use one of the following lines:

    C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Themes\Dark_Mode.theme
    

    or

    C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Themes\Light_Mode.theme
    

    Please note the path to the theme files might be needed to adjust depending on your system user configuration. I strongly advise saving your themes with names excluding spaces as it makes much easier moving forward. Executing such line leaving you with the Settings window opened. To deal with I considered using VBS script instead. Thanks to Patrick Haugh user1390106 there is a much easier way to close the Settings window.

    taskkill /F /IM systemsettings.exe
    

    So the updated version of batch file could look like this:

    @echo off
    if %1 == dark (
    REM ================== Go Dark ==================
    color 09
    echo.
    echo   Applying DARK MODE
    echo   Windows Theme ...
    C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Themes\Dark_Mode.theme
    timeout /T 1 /nobreak > nul
    taskkill /F /IM systemsettings.exe > nul
    echo   DONE
    ) else (
    REM ============== Return to Light ==============
    color 30
    echo.
    echo   Applying LIGHT MODE
    echo   Windows Theme ...
    C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Themes\Light_Mode.theme
    timeout /T 1 /nobreak > nul
    taskkill /F /IM systemsettings.exe > nul
    echo   DONE
    )
    REM ================== Goodbye ==================
    echo.
    echo   Goodbye
    cls
    exit
    

    Please note the path to the theme files might be needed to adjust depending on your system user configuration. Save above script with the name theme.bat somewhere in your drive. This batch file taking one parameter which needs to be either dark or any other string. Then you could prepare two shortcuts to this batch file each with one of the following in the box called “Target” on the “Shortcut” tab in its properties:

    C:\full-path-to-your-batch-file\theme.bat dark
    

    or

    C:\full-path-to-your-batch-file\theme.bat light
    

    Please replace “full-path-to-your-batch-file” with actual path to that file. Here are links to the videos showing how this works:

    a) Going Dark – https://youtu.be/cBcDNhAmfyM

    b) Returning to the Light – https://youtu.be/2kYJaJHubi4

    Please note that my script in those videos also activating/deactivating the Stylish plug-in for chrome. I have omitted to explain how I accomplished that part as it is not a subject of this article.

提交回复
热议问题