
You should wait a sec before sending WM_CLOSE.

So if you start it with the monstrous (but genious) rundll32.exe method suggested by "Campbell". Meaning that in the SendMessages returns, you know that the theme dialog is closed. The difference is that SendMessage waits for the command to be taken in by the window. I use SendMessage instead of PostMessage. In addition of the post of "Jan Goyvaerts": While (!bExited & counter 0 & args.ToLower(CultureInfo.InvariantCulture).Equals("basic")))Ĭonsole.WriteLine("Setting to basic.") Įlse if (args.Length > 0 || args.ToLower(CultureInfo.InvariantCulture).Equals("aero")) P.StartInfo.WindowStyle = ProcessWindowStyle.Minimized Private String StartProcessAndWait(string filename, string arguments, int seconds, ref Boolean bExited) Private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam) Private static extern IntPtr FindWindow(string sClassName, string sAppName) So starting from Mike's post above I cleaned things up, added comments, and will post full C# console app code: I know this is an old ticket, but somebody asked me how to do this today. This isn't a very elegant solution, but it does the job. Call PostMessage(HWND, WM_CLOSE, 0, 0) to close the Control Panel window.The "Personalization" caption will likely be different on non-US-English versions of Windows.


an automated test tool may need to switch between various themes to make sure the application works correctly with all of them.Īs a user, you can change the theme by double-clicking a. There are certainly good reasons for wanting to change the current theme programmatically.
