To use it, copy and save the code to a .vbs file and put it in your startup folder if you want it to start automatically.
Expand|Select|Wrap|Line Numbers
- Option Explicit
- Dim WshShell, oFolder, intNumber, strValue, i, oFile, strFolder, intFolders, intFiles, serialIndex, sleepTime, serialFolder
- strFolder = "C:\Documents and Settings\username\My Documents\My Pictures\Wallpapers\"
- Set WshShell = WScript.CreateObject("Wscript.Shell")
- Set oFolder = WScript.CreateObject("Scripting.FileSystemObject").GetFolder(strFolder)
- serialIndex = 0
- Do While True
- Do While True
- If serialIndex > 0 Then
- serialIndex = serialIndex + 1
- If serialIndex > serialFolder.Files.Count Then serialIndex = 0
- End If
- If serialIndex > 0 Then
- i = 0
- For Each oFile In serialFolder.Files
- i = i + 1
- If i = serialIndex Then Exit For
- Next
- Else
- intFiles = oFolder.Files.Count
- intFolders = oFolder.Subfolders.Count
- Randomize
- intNumber = Int((intFiles + intFolders) * Rnd) + 1
- If intNumber > intFiles Then
- sleepTime = 5000
- serialIndex = 1
- i = intFiles
- For Each serialFolder In oFolder.Subfolders
- i = i + 1
- If i = intNumber Then Exit For
- Next
- i = 0
- For Each oFile In serialFolder.Files
- i = i + 1
- If i = serialIndex Then Exit For
- Next
- Else
- sleepTime = 600000
- i = 0
- For Each oFile In oFolder.Files
- i = i + 1
- If i = intNumber Then Exit For
- Next
- End If
- End If
- If oFile.Path <> strValue Then
- strValue = oFile.Path
- Exit Do
- End If
- Loop
- Set oFile = Nothing
- WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strValue
- WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
- WScript.Sleep sleepTime
- Loop
- Set WshShell = Nothing
- Set oFolder = Nothing