' Wallpaper.vbs - Changes the desktop wallpaper to a random image ' Images are stored in "My Pictures\Wallpaper" ' Images nust be in BMP format ' ' Author: Simon Kennedy ' Version: 1.1 ' Date: 2010-03-20 ' ' History: 1.0 initial version ' 1.1 Fixed so actually selects a random image correctly Option Explicit Randomize Const VERBOSE = 0 Const MY_DOCUMENTS = &H5& Const MY_PICTURES = &H27& Const COMMON_FILES = &H2b& Const WALLPAPER_CENTER = 0 Const WALLPAPER_TILE = 1 Const WALLPAPER_STRETCH = 2 Const WALLPAPER_FOLDER = "\Wallpaper" Dim WSHShell Set WSHShell = WScript.CreateObject("WScript.Shell") If VERBOSE = 1 Then WScript.Echo "Setting random wallpaper to..." End If Dim objShell, objFolder Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(MY_PICTURES) Dim strWallpaperFolder strWallpaperFolder = objFolder.Self.Path & WALLPAPER_FOLDER Dim fso set fso = CreateObject("Scripting.FileSystemObject") Set objFolder = fso.GetFolder(strWallpaperFolder) Dim colFiles Set colFiles = objFolder.Files Dim colItems Set colItems = CreateObject("Scripting.Dictionary") Dim strFilename, objFile, intItemNum intItemNum = 0 For Each objFile in colFiles strFilename = objFile.Name If Right(strFilename, 4) = ".bmp" Then colItems.Add intItemNum, strFilename intItemNum = intItemNum + 1 End If Next Dim index index = Int(colItems.Count * Rnd) strFilename = colItems(index) If VERBOSE = 1 Then WScript.Echo strWallpaperFolder & "\" & strFilename End If WSHShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper", strWallpaperFolder & "\" & strFilename WSHShell.RegWrite "HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle", WALLPAPER_STRETCH WSHShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False Set WSHShell = Nothing WScript.Quit