Link to home
Start Free TrialLog in
Avatar of Nebulus
Nebulus

asked on

Changing and updating the desktop wallpaper - only in vbscript

Hey all. I've got a vbscript that I wrote that will make the necessary change to the registry to set an HTML file as the desktop wallpaper.

The only problem I'm having is actually getting the desktop to refresh so that the new wallpaper is displayed. The code I have does manage to send an F5 keystroke to refresh the screen, but the wallpaper doesn't show up. When I access the display properties, I can see that the wallpaper is selected, so how do you get it to show up once you've set the registry value?

**********************************************
BEGIN CODE
**********************************************
' Create the variables needed
Dim WSHShell
Dim strRegKey
Dim strWallpaper
Dim strDesktop

' Create the Wscript Shell object
Set WSHShell = WScript.CreateObject("WScript.Shell")

' Define the wallpaper
strWallpaper = "%SystemRoot%\Web\Wallpaper\PRWeb.html"
strDesktop    = WSHShell.SpecialFolders("Desktop")

' Create the wallpaper key
strRegKey =  "HKEY_CURRENT_USER\"
strRegKey = strRegKey & "Software\"
strRegKey = strRegKey & "Microsoft\"
strRegKey = strRegKey & "Internet Explorer\"
strRegKey = strRegKey & "Desktop\"
strRegKey = strRegKey & "General\"
strRegKey = strRegKey & "Wallpaper"

' Write the key, type, and value
WSHShell.RegWrite strRegKey, strWallpaper, "REG_EXPAND_SZ"

' Refresh the desktop now.
WSHShell.AppActivate strDesktop
WSHShell.SendKeys "{F5}"

' Quit
Wscript.quit(0)
**********************************************
END CODE
**********************************************
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nebulus
Nebulus

ASKER

That worked perfectly! I made some *minor*changes, and here's the final code. Thanks for the help!

' Create the variables needed
Dim WSHShell
Dim WSHApp
Dim strRegKey
Dim strWallpaper
Dim strOSRoot
Dim strDesktop
Dim strDisplayProp

' Create the Wscript Shell object
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set WSHApp   = CreateObject("Shell.Application")

' Define the wallpaper
strWallpaper   = "%SystemRoot%\Web\Wallpaper\PRWeb.html"
strDesktop     = WSHShell.SpecialFolders("Desktop")
strDisplayProp = "Display Properties"

' Create the wallpaper key
strRegKey =  "HKEY_CURRENT_USER\"
strRegKey = strRegKey & "Software\"
strRegKey = strRegKey & "Microsoft\"
strRegKey = strRegKey & "Internet Explorer\"
strRegKey = strRegKey & "Desktop\"
strRegKey = strRegKey & "General\"
strRegKey = strRegKey & "Wallpaper"

' Write the key, type, and value
WSHShell.RegWrite strRegKey, strWallpaper, "REG_EXPAND_SZ"

' Refresh the desktop now.
WSHApp.ControlPanelItem cstr("desk.cpl")
Do Until WSHShell.AppActivate (strDisplayProp)
Loop
WSHShell.SendKeys "{down}{up}{tab 3}a~"