Option Explicit

Const INTERVAL = 60 '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")

'get the location of the user and shared wallpaper folders
Dim dirWps(1)
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")

Dim i
For i = 0 To UBound(dirWps)
	If Right(dirWps(i), 1) <> "\" Then dirWps(i) = dirWps(i) & "\"
Next

Do While True
	'enumerate available wallpapers
	Dim fldWp, fileWp, nextOne, nextWp, firstWp, fileWpFullName
	For i = 0 To UBound(dirWps)
		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
	Next
Loop