We help IT Professionals succeed at work.

Setting Theme via shell script on Windows 10

Eddie Shipman
Eddie Shipman used Ask the Experts™
on
I have a shell script that I've been using for Windows 7. It sets the theme for my system desktop. It no longer works now that I've moved to Windows 10.
With WScript.CreateObject("WScript.Shell")
    WScript.echo "Open Theme dialog and select theme and then close"

    .Run "rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""%UserProfile%\AppData\Local\Microsoft\Windows\Themes\MyPersonal.theme"""
    For i = 1 To 10
            WScript.Sleep 5000
        If .AppActivate("Personalization") Then
           .Sendkeys "%FC"
           .Sendkeys "{F4}"
           Exit For
        End If
    Next
End With

Open in new window

I know I can open the Themes dialog using the run command and
ms-settings:themes

Open in new window

But how would I this as well as select the theme and close the dialog in a shell script on Windows 10?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Eddie ShipmanAll-around developer

Author

Commented:
That is Powershell. I'm running VBScript,
This command works for me

"%UserProfile%\AppData\Local\Microsoft\Windows\Themes\MyPersonal.theme" & timeout /t 5 & taskkill /F /IM systemsettings.exe

Open in new window

Test your restores, not your backups...
Top Expert 2016
Commented:
Building off of what you have now, you could try this...

With WScript.CreateObject("WScript.Shell")
    WScript.echo "Open Theme dialog and select theme and then close"
    .Run .ExpandEnvironmentStrings("%UserProfile%\AppData\Local\Microsoft\Windows\Themes\MyPersonal.theme")
    For i = 1 To 10
            WScript.Sleep 5000
        If .AppActivate("Personalization") Then
           .Sendkeys "%{F4}"
           Exit For
        End If
    Next
End With

Open in new window


»bp