Welcome Guest.   Make a donation to an author on the site July 25, 2014, 06:19:53 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2012! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: DONE: VBS set wallpaper from folder of backgrounds  (Read 4042 times)
Coniferous
Supporting Member
**
Posts: 10


View Profile Give some DonationCredits to this forum member
« 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.
Logged
Winkie
Supporting Member
**
Posts: 82


View Profile Give some DonationCredits to this forum member
« 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 undecided.
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):
Formatted for Visual Basic with the GeSHI Syntax Highlighter [copy or print]
  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

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

HTH,
Greetings Winkie
Logged
iskander71
Participant
*
Posts: 3


View Profile Give some DonationCredits to this forum member
« 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 !!
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.034s | Server load: 0.06 ]