A simple .NET Worker Service that automatically switches Windows system appearance mode (Light/Dark) based on the time of day.
- Once every hour, the service checks the current time.
- If the time is between 8 PM and 6 AM, it switches to Dark Mode.
- Otherwise, it switches to Light Mode.
- The service updates Windows registry keys:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\PersonalizeAppsUseLightThemeandSystemUsesLightThemevalues are changed.
- After changing the registry, it broadcasts a
WM_SETTINGCHANGEmessage so apps that support it can refresh.
- .NET 8 Worker Service
- Microsoft.Extensions.Hosting.WindowsServices
- Runs as a native Windows Service.
-
Publish the service:
dotnet publish -c Release -o "C:\MyServices\AppearanceToggleService" -
Open an elevated Command Prompt and install the service:
sc create AppearanceToggleService binPath= "C:\MyServices\AppearanceToggleService\AppearanceToggleService.exe" sc start AppearanceToggleService -
To stop or uninstall:
sc stop AppearanceToggleService sc delete AppearanceToggleService
/AppearanceToggleService ├─ Worker.cs # Main background service logic ├─ ThemeManager.cs # Handles registry changes ├─ SystemThemeNotifier.cs # Broadcasts WM_SETTINGCHANGE ├─ Program.cs # Entry point for the worker └─ README.md
-
Since the service runs in the system context, you must ensure it affects the correct user’s registry. This project uses
Registry.CurrentUser, which works if the service runs under your user account. Otherwise, extra steps are needed to write to the correctHKEY_USERS\<SID>. -
Tested on Windows 11. Behavior may vary on older versions.
Feel free to use and modify this project.