Reputation: 41
How to programmatically switch between dark and light mode for Windows. I used registry keys,
HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\SystemUsesLightTheme
But it does not execute the command directly like a toggle switch in the Color Settings\Personalize\Colors window.
Windows does not respond immediately to dark or light mode changes via registry keys
Upvotes: 3
Views: 2606
Reputation: 1512
Based on Bender's answer. I created one file, which can toggle between light and dark themes.
Create toggleWinTheme.ps1.
Paste the code below and save
Then right click on the file and select Run with PowerShell
# Get the current mode
$currentMode = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme
# Toggle the mode
if ($currentMode -eq 1) {
# If currently in Light Mode, switch to Dark Mode
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0
Write-Output "Switched to Dark Mode"
} else {
# If currently in Dark Mode, switch to Light Mode
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1
Write-Output "Switched to Light Mode"
}
Upvotes: -2
Reputation: 1250
You can trigger an event in Windows tasks scheduler for every mode you want (light and dark, for example). There, in actions tab, set "start a program" with Powershell in program or script (type the following line):
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
And in "add optional args", insert this line (change AppsUseLightTheme
for the var you wanna set and the value 0/1 depending on the time of day):
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1
Also, to answer some of the comments in @Bender110001 answer, you got 2 vars for custom theme in Win11 (maybe 10 too):
AppsUseLightTheme
for applications (Pycharm, browser pages, etc)SystemUseLightTheme
for system colors (as you can see in the Win customization manual config: taskbar, windows, OS style out of apps).Upvotes: -1
Reputation: 331
You can use PowerShell scripts to achieve that. Example:
Enable Darkmode on Apps
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force
Enable Lightmode on Apps
Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme
Upvotes: 2