Skip to content

Instantly share code, notes, and snippets.

@ADeltaX
Created May 22, 2020 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ADeltaX/ff12b127896d34ef3f2ed0c4598a0752 to your computer and use it in GitHub Desktop.
Save ADeltaX/ff12b127896d34ef3f2ed0c4598a0752 to your computer and use it in GitHub Desktop.
Change Theme color (Dark/Light mode) FAST!
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam);
static void Main(string[] args)
{
int LightTheme = 0;
if (args.Length > 0)
{
if (int.TryParse(args[0], out var val))
{
if (val > 1)
LightTheme = 1;
else if (val < 0)
LightTheme = 0;
else
LightTheme = val;
}
}
RegistryKey k = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default);
var wr = k.OpenSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", true);
wr.SetValue("AppsUseLightTheme", LightTheme, RegistryValueKind.DWord);
wr.SetValue("SystemUsesLightTheme", LightTheme, RegistryValueKind.DWord);
SendNotifyMessage((IntPtr)0xffff /* Broadcast */, 0x031A, (UIntPtr)0, ""); //WM_THEMECHANGED
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment