Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 01, 2015, 05:22:06 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: VBS set wallpaper from folder of backgrounds  (Read 4824 times)

Coniferous

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 10
    • View Profile
    • Donate to Member
DONE: VBS set wallpaper from folder of backgrounds
« on: September 27, 2010, 09:02:49 AM »
This is more of a frilly not important request,

But I would like a script that gets called on startup that changes my wallpaper to a randomly chosen image the lies in a folder contained in my documents.

(how’s that for a run-on sentence?).

Not sure how difficult this is, if it's harder then it seems let me know.

Winkie

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 82
    • View Profile
    • Donate to Member
Re: VBS set wallpaper from folder of backgrounds
« Reply #1 on: September 27, 2010, 03:54:44 PM »
Not sure how difficult this is, if it's harder then it seems let me know.
It's not that difficult to script this in VBS, my limited VBS/VBA knowledge and some Googling was enough :-\.
But since you want an VBS-script it will remain very limited as far as I know. Because it only works with a folder with only bitmaps (*.bmp) with a size in pixels which exactly match your screen dimensions.

Anyway, here's the script (tested in WinXP):
Code: Text
  1. ' WallpaperChanger.vbs - by Winkie - Last changed: 20100927
  2. Option Explicit
  3.  
  4. Dim oShell, oScripting, aFilesArray
  5. Dim sWallpaperDir, sFolder, sFile
  6. Dim i , iFiles, iSelection
  7.  
  8. sFolder = "E:\Test\" ' Include quotes and last backslash
  9.  
  10. Set oShell = CreateObject("WScript.Shell")
  11. Set oScripting = CreateObject("Scripting.FileSystemObject")
  12.  
  13. Set sFolder = oScripting.GetFolder(sFolder)
  14.  
  15. iFiles = CInt(sFolder.Files.Count)
  16.  
  17. ReDim aFilesArray(0)
  18. For Each sFile in sFolder.Files
  19.    ReDim Preserve aFilesArray(UBound(aFilesArray) + 1)
  20.    aFilesArray(UBound(aFilesArray)) = sFile.ShortPath
  21. Next
  22.  
  23. i = 1
  24. Randomize
  25. iSelection = Int((UBound(aFilesArray) - i + 1) * Rnd + i)
  26.  
  27. oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", aFilesArray(iSelection)
  28. oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, False
  29.  

If it doesn't necessarily have to be an VBS-script, I'm sure an AutoHotkey-script can solve the limitations.

HTH,
Greetings Winkie

iskander71

  • Participant
  • Joined in 2010
  • *
  • Posts: 3
    • View Profile
    • Donate to Member
Re: VBS set wallpaper from folder of backgrounds
« Reply #2 on: October 19, 2010, 03:58:45 AM »
Wouaw, personnaly I am a newbeet so bravo !!
I want to learn but I don' t know where begin, with wich language, etc...and with wich 'editor' write all this coding, like yours here !!!!

Year I know, but I hope I will learn !!