...

View Full Version : VBScript Random file selector



carrot
06-12-2009, 02:47 AM
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:



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum