Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random File Choser

Status
Not open for further replies.

mew1033

IS-IT--Management
Jun 11, 2009
1
US
Hi
I'm making a random wallpaper switcher, and I've hit a snag. I'm using the awesome software Ultramon, and I've ALMOST got what I want.
I have a script that changes the wallpaper on a set interval, the only problem is it's not random. It just uses the next file in the folder.

Here is the script I have so far:



Code:
Option Explicit

Const INTERVAL = 20 'interval between wallpaper changes in minutes
Const UMDESKTOP_EXE = "%ProgramFiles%\UltraMon\UltraMonDesktop.exe"

Dim sh, fso
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

'check if UltraMon 3 or later is installed
Dim umVer
umVer = sh.RegRead("HKLM\Software\Realtime Soft\UltraMon\CurrentVersion")

'get the location of the wallpaper folder(s)
Dim dirWps(1)
If umVer = "" Then
	'UltraMon 2, location of the user and shared wallpaper folders stored in the registry
	dirWps(0) = sh.RegRead("HKCU\Software\Realtime Soft\UltraMon\Wallpaper\Wallpaper Directory")
	dirWps(1) = sh.RegRead("HKLM\Software\Realtime Soft\UltraMon\Wallpaper\All Users Wallpaper Directory")
Else
	'UltraMon 3 or later, wallpaper folder is at a known location
	dirWps(0) = sh.ExpandEnvironmentStrings("%APPDATA%\Realtime Soft\UltraMon\" & umVer & "\Wallpapers")
End If

Dim i
For i = 0 To UBound(dirWps)
	If dirWps(i) <> "" Then
		If Right(dirWps(i), 1) <> "\" Then dirWps(i) = dirWps(i) & "\"
	End If
Next

Do While True
	'enumerate available wallpapers
	Dim fldWp, fileWp, fileWpFullName
	For i = 0 To UBound(dirWps)
		If dirWps(i) <> "" Then
			Set fldWp = fso.GetFolder(dirWps(i))
			For Each fileWp In fldWp.Files
				If Right(fileWp.Name, 10) = ".wallpaper" Then
					fileWpFullName = dirWps(i) & fileWp.Name
					
					'load next wallpaper
					Dim cmd : cmd = """" & UMDESKTOP_EXE & """ /load " & fileWpFullName
					sh.Run cmd
					
					'wait
					WScript.Sleep INTERVAL * 60 * 1000
				End If
			Next
		End If
	Next
Loop



Can anyone help me put a randomizer in this script?

Thanks!!

Chandler

 
Add all the pictures into an array. Then grab a random number to act as the index to pull out of the array to display your wallpaper.

Here is code to generate a random number between 1 and 100.

Code:
randomize()
randomNumber=Int(100 * rnd())

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top