Script to Change Desktop Background

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Image Credit: Brusonja/iStock/Getty Images

Most users don't realize it, but Microsoft installs a copy of their Visual Basic Script language on every Windows computer. This simple but powerful language makes it possible to automate nearly every task a user or administrator will need to perform on a system, such as change the desktop background.

Advertisement

Text Editor

Video of the Day

Creating a Visual Basic Script is easy: all you need is a simple text editor such as Windows Notepad. However, instead of saving the file with a name that ends in ".TXT," the file must be saved with a name ending in ".VBS."

Advertisement

Video of the Day

The Script

Paste the following into a text editor:

dim shell dim user

Set shell = WScript.CreateObject("WScript.Shell") user = shell.ExpandEnvironmentStrings("%USERNAME%")

Advertisement

Set fso = CreateObject("Scripting.FileSystemObject")

windowsDir = fso.GetSpecialFolder(0) wallpaper = "c:\wallpaper.jpg"

shell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper

Advertisement

Advertisement

shell.Run "%windowsDir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

Change the file "c:\wallpaper.jpg" to the path and filename of the desktop background you would like to use.

Advertisement

How to Run

To run the script, simply save it with the file extension .VBS. Then, double-click its icon on your Desktop with your mouse as you would to start any other program.

Advertisement

Advertisement

references