DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: DONE: VBS set wallpaper from folder of backgrounds  (Read 13,331 times)

Coniferous

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 10
DONE: VBS set wallpaper from folder of backgrounds
« on: September 27, 2010, 02:02 PM »
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: 94
    • Participated in NANY Challenge Once
Re: VBS set wallpaper from folder of backgrounds
« Reply #1 on: September 27, 2010, 08:54 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: (vb)
' WallpaperChanger.vbs - by Winkie - Last changed: 20100927
Option Explicit

Dim oShell, oScripting, aFilesArray
Dim sWallpaperDir, sFolder, sFile
Dim i , iFiles, iSelection

sFolder = "E:\Test\" ' Include quotes and last backslash

Set oShell = CreateObject("WScript.Shell")
Set oScripting = CreateObject("Scripting.FileSystemObject")

Set sFolder = oScripting.GetFolder(sFolder)

iFiles = CInt(sFolder.Files.Count)

ReDim aFilesArray(0)
For Each sFile in sFolder.Files
   ReDim Preserve aFilesArray(UBound(aFilesArray) + 1)
   aFilesArray(UBound(aFilesArray)) = sFile.ShortPath
Next

i = 1
Randomize
iSelection = Int((UBound(aFilesArray) - i + 1) * Rnd + i)

oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", aFilesArray(iSelection)
oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, False

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
Re: VBS set wallpaper from folder of backgrounds
« Reply #2 on: October 19, 2010, 08:58 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 !!

Original address: https://www.donationcoder.com/forum/index.php?topic=24117.0