Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the current Windows theme programmatically?

Tags:

windows

themes

I want to allow my users to toggle the current user theme between Aero and Windows Classic(1). Is there a way that I can do this programatically?

I don't want to pop up the "Display properties", and I'm dubious about just changing the registry. (This requires a log out and a log back in for the changes to take effect).

Application skinning (using the Codejock libraries) doesn't work either.

Is there a way of doing this?

The application is hosted/run on a Windows Server 2008 over RDP.

(1) The application in question is a hosted "Remote App", and I want users to be able to change the look of the displayed application to match their desktop.

like image 486
seanyboy Avatar asked Feb 13 '09 17:02

seanyboy


People also ask

How do I change my custom Windows theme?

Right-click in any blank space on the desktop. Select Personalize from the drop-down menu that appears. On the left side, select Themes, and then Theme settings. In the Personalize window that appears, click the Get more themes online option.

How do I change the synced theme in Windows 10?

Go to Settings > Accounts > Sync your settings. From the right-hand pane, select Individual sync settings. Toggle the Theme setting to off. That's all there is to it!

Can I edit a Windows theme?

Please be informed that there is no option to edit themes in Windows 10. How ever you can create your own theme using your favorite photos. Also you can use your favorite web browser and search for any theme creator program which can help you edit the themes.

Where are Windows theme Settings stored?

%localappdata%\Microsoft\Windows\Themes Press the Enter key to open the Themes folder. Step 2: The Themes folder contains all installed themes. You can double-click on a theme's folder to see the desktop theme file as well as the Desktop Background folder which includes all the wallpapers of that theme.


2 Answers

You can set it using the following command:

rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:"C:\Windows\Resources\Themes\aero.theme" 

Caveat is that this will show the theme selector dialog. You could kill that dialog straight after.

like image 186
Campbell Avatar answered Sep 28 '22 20:09

Campbell


There are certainly good reasons for wanting to change the current theme programmatically. E.g. an automated test tool may need to switch between various themes to make sure the application works correctly with all of them.

As a user, you can change the theme by double-clicking a .theme file in Windwos Explorer and then closing the Control Panel applet that pops up. You can easily do the same from code. The steps below work just fine for me. I've only tested on Windows 7.

  1. Use SHGetKnownFolderPath() to get the "Local AppData" folder for the user. Theme files are stored in the Microsoft\Windows\Themes subfolder. Theme files stored there are applied directly, while theme files stored elsewhere are duplicated when you execute them. So it's best to use files from that folder only.
  2. Use ShellExecute() to execute the .theme file you located in step 1.
  3. Wait for the theme to be applied. I simply let my app sleep for 2 seconds.
  4. Call FindWindow('CabinetWClass', 'Personalization') to get the handle of the Control Panel window that popped up when the theme was applied. The "Personalization" caption will likely be different on non-US-English versions of Windows.
  5. Call PostMessage(HWND, WM_CLOSE, 0, 0) to close the Control Panel window.

This isn't a very elegant solution, but it does the job.

like image 33
Jan Goyvaerts Avatar answered Sep 28 '22 21:09

Jan Goyvaerts