Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Set Random Desktop Wallpaper On Startup
 

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.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
          - Add Remove Windows Server 2003 Components
          - Add Remove Windows Vista Components
          - Add Remove Windows Xp Components
          - Autologon And Runonce
          - Change Display Resolution
          - Change Location I386 Setup Files
          - Change Offline Folder Cache Location
          - Dell Bios Set Boot Device Order
          - Dell Bios Set Configuration Settings
          - Dell Bios View Configuration Settings
          - Dell Bios View Device Boot Order
          - Disable Vista User Account Control
          - Enumerate Cd Drives
          - Enumerate Computer Drives
          - Enumerate Disk Volumes
          - Enumerate Registry Keys
          - Flush Remote Dns Cache
          - Get Machine Hardware Model
          - Read Registry Key
          - Rename Computer
          - Rename Dell Machine By Service Tag
          - Set Internet Explorer Homepage
          - Set Random Desktop Wallpaper On Startup
          - Start And Stop A Service
          - Windows Login Timer
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers