Reputation: 137
I have written a vbscript that will automatically change the theme to my desktop using cmd, and then close the "Personalization" window after it is changed. In order to give enough time to the rest of my code, I place a timer of 3500 ms after a line of code to allow the rest of it to run after it has finished executing. I'm wondering if there is a way to take out the timer but still allow the Personalization window to close automatically after the theme is changed. I tried using a "true" statement at the end of the line, but it doesn't seem to work and the window stays open and I have to manually close it. My code is as follows:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""C:\Windows\Resources\Ease of Access Themes\basic.theme"""
Wscript.Sleep 3500
WshShell.AppActivate("Desktop Properties")
WshShell.Sendkeys "%FC"
WshShell.Sendkeys "{F4}"
Also, I am not sure what the %FC and {F4} mean at the end (some of these lines I got from other sources, but it just seemed to work at the time). Thank you in advance for any help!
Upvotes: 0
Views: 292
Reputation: 2251
You can accomplish this by:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "rundll32.exe %SystemRoot%\system32\shell32.dll,Control_RunDLL %SystemRoot%\system32\desk.cpl desk,@Themes /Action:OpenTheme /file:""C:\Windows\Resources\Ease of Access Themes\basic.theme"""
Wscript.Sleep 3500
WshShell.AppActivate("Desktop Properties")
WshShell.Sendkeys "%FC"
WshShell.AppActivate("Desktop Properties")
WshShell.Sendkeys "%{F4}"
That being said, if you run scripts on your machine you should really know what your code does. A six line script and you don't know what two of them do is asking for trouble.
Upvotes: 1