Vbscript / Operating System / Set Random Desktop Wallpaper On Startup
This script will select a random picture (jpg) from a specified folder (default My Pictures), convert the picture to BMP and set it as the desktop wallpaper on next boot.
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWShell = WScript.CreateObject("WScript.Shell")
strProfile = objWShell.ExpandEnvironmentStrings("%USERPROFILE%")
strSrcPath = strProfile & "\My Documents\My Pictures\"
intMaxLenth = 500 intMinLength = 1
Randomize
intMax = Int(((intMaxLenth - intMinLength + 1) * Rnd))
dirScan strSrcPath,0,intMax
Sub dirScan(dir, count, max)
If count > max Then Exit Sub End If
Set objDir = objFSO.getFolder(dir) For Each objItem in objDir.Files
If NOT count > max Then
If objFSO.GetExtensionName(objItem.Path) = "jpg" Then count = count + 1 End If
If count > max Then
setWallpaper objItem.Path
End If
End If
Next
For Each objSubDir in objDir.SubFolders
If NOT count > max Then dirScan objSubDir.Path,count, max End If
Next End Sub
Sub setWallpaper(strSrcPic)
Set objShell = WScript.CreateObject("WScript.Shell")
strWallPath = objShell.ExpandEnvironmentStrings("%APPDATA%") & "\Microsoft\Wallpaper1.bmp"
objShell.Run "mspaint """ & strSrcPic & """"
Do Until Success = True Success = objShell.AppActivate("Paint") Wscript.Sleep 100 Loop
objShell.SendKeys "%fa" objShell.SendKeys strWallPath objShell.SendKeys "{TAB}" objShell.SendKeys "22" objShell.SendKeys "%s" Wscript.Sleep 500 objShell.SendKeys "y"
Success = false Wscript.Sleep 1000 Success = objShell.AppActivate("Paint")
objShell.SendKeys "%{f4}"
objShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strWallPath
End Sub
Please note that a disclaimer applies to any code on this page.
|