Programatically change Windows 11 Theme using theme file

simonwait

New member
Joined
Jul 11, 2025
Messages
1
Programming Experience
Beginner
Hi

I'm trying to change the Windows theme based on the PC name of the machine. I think most things work however, I can't seem to get it to change. Although I can double click the .theme file in Explorer and it changes in my C# code it returns.

System.ComponentModel.Win32Exception: 'The specified executable is not a valid application for this OS platform.'

Thanks in advance for any suggestions.

C#:
Expand Collapse Copy
            string CurrentTheme = (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\", "CurrentTheme", null);
            string myLastSubString = CurrentTheme.Split('\\').Last();
            txtCurrentTheme.Text = myLastSubString;
            txtPCName.Text = Environment.MachineName;

            if (txtCurrentTheme.Text != txtPCName.Text + ".theme")
            {

                var filename = "C:\\Themes\\STS_Theme-" + txtPCName.Text + ".theme";
                System.Diagnostics.Process.Start(filename);
            }
 
This isn't a WinForms specific question, I'll try to move the thread.

Anyway, are you using .NET Framework, or .NET (Core) 8.0 or higher? I think the default behavior changed between .NET Framework and .NET Core. Try explicitly using the version of Start() that takes a ProcessStartInfo where you set UseShellExecute to true and set the FileName to you point to your theme file.
 
Back
Top Bottom