Life of Muff

Friday, September 22, 2006

Randomize Your Destop Background

Can't choose which desktop background you want? Or perhaps you get sick of your background after a just a few days? Here's your solution: randomize your desktop background!

I actually fit into both of the above categories. That prompted me to write a short script to change the background on startup. All you need to do is place the script in the same folder as your backgrounds, and add a shortcut in the startup folder. The only restraint is that it will only work with BMP files.

Here's what to do:

1) Save this file into the directory where your BMP backgrounds reside.

2) Create a shortcut to the file and put that shortcut to the Startup folder. Done!

Now, everytime you load Windows a BMP background will be randomly selected from the directory that the script resides.

For the developers, here's the source:

'====================
'
' VBScript Source File
'
' NAME: alternateBG.vbs
'
' AUTHOR: Mark Lee
' E-mail: mark.lee@internode.on.net
'
' DATE : 23/10/2005
'
' COMMENT: Alternate the desktop background image.
' Place this script in a directory with two or
' more BMP images. When run, this script will
' randomly select one of these BMP images and
' set it as the desktop background. Place a
' shortcut to this file in the Startup folder
' to change the background each time you boot.
'====================

Dim WshShell, dimensioned, pics(), Wallpaper
Dim FSO, folder, file, files, i

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set folder = FSO.GetFolder(WshShell.CurrentDirectory)
Set files = folder.Files

dimensioned = False

For Each file in files
If Lcase(Right(file.Name, 3)) = "bmp" Then

If dimensioned = False Then
ReDim Preserve pics(0)
dimensioned = True
Else
ReDim Preserve pics(UBound(pics) + 1)
End If

pics(Ubound(pics)) = file.Name

End If
Next

Randomize
Wallpaper = "HKCU\Control Panel\Desktop\Wallpaper"
SetBGPic(pics(Int((Ubound(pics) + 1) * Rnd)))

Set FSO = Nothing

Function SetBGPic(picname)

WshShell.RegWrite Wallpaper, WshShell.CurrentDirectory & "\" & picname, "REG_SZ"
WshShell.run "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"

End Function

0 Comments:

Post a Comment

<< Home