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
You can use PowerShell scripts to achieve that. Example:
Enable Darkmode on Apps
Enable Lightmode on Apps