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
**********************************************
NebulusAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bruintjeCommented:
In addition to the logon/logoff you can consider this options also to refresh the desktop:

1. The correct (but "complicated") way of doing it:
Use the API SystemParametersInfo through an API wrapper or a COM object.

2. The "dirty" but simple way:
Use the Control panel applet desk.cpl and SendKeys to refresh the desktop.

Set oSHApp = CreateObject("Shell.Application")
Set oShell = CreateObject("WScript.Shell")

' set the desired wallpaper in registry ("HKCU\Control
Panel\Desktop\Wallpaper") using eg. RegWrite

oSHApp.ControlPanelItem cstr("desk.cpl")
' alt. oShell.Run "control desk.cpl"

Do Until oShell.AppActivate ("Display Properties")
Loop
oShell.SendKeys "{down}{up}{tab 3}a~"

If the {down}{up}- thing doesn't work for you, you must do something else in the control panel applet to activate a change (but that really not changes anything ;-) to "activate" the apply-button. NB! Key sequence is very often dependent on the language version of Windows.

source : http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3B7199E3.C72BC69F%40hydro.com
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NebulusAuthor Commented:
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~"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.