473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

Random Wallpaper Script

Rabbit
12,516 Expert Mod 8TB
I created this VBScript to randomize my wallpaper. It also uses subfolders for sequential images. It chooses from one of the files or folders in the specified parent folder at random. If it chooses a file, it waits 10 minutes to change it. If it chooses a folder, it will step through the pictures in order every 5 seconds.

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
  1. Option Explicit
  2. Dim WshShell, oFolder, intNumber, strValue, i, oFile, strFolder, intFolders, intFiles, serialIndex, sleepTime, serialFolder
  3.  
  4. strFolder = "C:\Documents and Settings\username\My Documents\My Pictures\Wallpapers\"
  5. Set WshShell = WScript.CreateObject("Wscript.Shell")
  6. Set oFolder = WScript.CreateObject("Scripting.FileSystemObject").GetFolder(strFolder)
  7. serialIndex = 0
  8.  
  9. Do While True
  10.     Do While True
  11.         If serialIndex > 0 Then
  12.             serialIndex = serialIndex + 1
  13.             If serialIndex > serialFolder.Files.Count Then serialIndex = 0
  14.         End If
  15.  
  16.         If serialIndex > 0 Then
  17.             i = 0
  18.             For Each oFile In serialFolder.Files    
  19.                 i = i + 1
  20.                 If i = serialIndex Then Exit For                                                            
  21.             Next
  22.         Else
  23.             intFiles = oFolder.Files.Count
  24.             intFolders = oFolder.Subfolders.Count
  25.             Randomize
  26.             intNumber = Int((intFiles + intFolders) * Rnd) + 1
  27.  
  28.             If intNumber > intFiles Then
  29.                 sleepTime = 5000
  30.                 serialIndex = 1
  31.                 i = intFiles
  32.                 For Each serialFolder In oFolder.Subfolders     
  33.                     i = i + 1
  34.                     If i = intNumber Then Exit For                                                            
  35.                 Next
  36.  
  37.                 i = 0
  38.                 For Each oFile In serialFolder.Files     
  39.                     i = i + 1
  40.                     If i = serialIndex Then Exit For                                                         
  41.                 Next
  42.             Else
  43.                 sleepTime = 600000
  44.                 i = 0
  45.                 For Each oFile In oFolder.Files     
  46.                     i = i + 1
  47.                     If i = intNumber Then Exit For                                                          
  48.                 Next
  49.             End If
  50.         End If
  51.  
  52.         If oFile.Path <> strValue Then
  53.             strValue = oFile.Path
  54.             Exit Do
  55.         End If
  56.     Loop
  57.     Set oFile = Nothing
  58.  
  59.     WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strValue
  60.     WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
  61.     WScript.Sleep sleepTime
  62. Loop
  63.  
  64. Set WshShell = Nothing
  65. Set oFolder = Nothing
  66.  
Jan 5 '11 #1
0 6723

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: robinpg.SHU | last post by:
As title really, does anyone know of (or could write?) a php file which in a directory of .jpg files display the most recent added to that /dir? Can anyone help?
3
by: Jennie Friesen | last post by:
Hello-- I would like to display a different line of text (32 different messages) on refresh, BUT with no repeats. The script I am currently using is: <script language=javascript...
3
by: Voetleuce en f?nsievry | last post by:
G'day I'm looking for a script that can search multiple instances of Google (or other search engines optionally). The user types in a single word in the text field, presses ENTER or the submit...
2
by: arwes | last post by:
I use a JavaScript to generate snowflakes on a HTML page. I want to calculate the size of the snowflakes by using th Math.random() function to get a great variety of snow flakes. I jus can't find...
6
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!--...
5
by: Linda | last post by:
Greetings: I have found a random image script that I like. It is located here: http://www.javascriptcity.com/scripts/local/simage3.htm I'd like to edit this to have 4 different slots for...
15
by: Papajo | last post by:
Hi, This script will write a random number into a document write tag, I've been trying to get it to write into a input form box outside the javascript, any help is appreciated. Thanks Joe ...
6
by: RTB | last post by:
I've been trying to replace my old PHP/iframe random quotes script with a PHP/javascript without success. http://www.just-quotes.com/wow/random.php <script...
2
by: Millie88 | last post by:
I am getting an error on the random.js var size and no tip is showing. Any help is appreciated! <html> <head> <!-- The Home Center Filename: home.htm
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.