Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ideally, I'd like to be able to do this through a batch file or VB script, so I can schedule it to run at different times of the day (dark wallpaper at night vs. light wallpaper at day).

I am aware of the many applications which could do this, but I prefer to keep only necessary applications running in the background.

share|improve this question

4 Answers 4

up vote 6 down vote accepted

You can use scheduled tasks along with this VBScript I just hacked together (this is for using multiple wallpapers and switching every few minutes for example):

Randomize
Set obshell = WScript.CreateObject("Wscript.Shell")
num = Int( ( 100 - 1 + 1 ) * Rnd + 1 )
CurrentDir = "C:\Wallpapers\day\"
wallpaper = CurrentDir & "Wallpaper" & num & ".bmp"
obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
UpdatePerUserSystemParameters",1,False
Set obshell = Nothing

Note: Wallpapers must be bitmaps. If you want to avoid more scripting to check system time periodically, you can use the same script for night and day just make a separate scheduled task and run it at the desired time at the desired interval. Make 2 folders, one for day wallpapers and one for night wallpapers, put a copy of the script in each. You'll need to change the 100 in line 3 to however many wallpapers are in each, and rename them to Wallpaper1, Wallpaper2, etc for this script to work (or modify the name in the script). Also modify the CurrentDir value for each.

If you'd like to only use 2 wallpapers (set it to run every 59 minutes or so to ensure you don't miss an hour):

Set obshell = WScript.CreateObject("Wscript.Shell")
CurrentHour = Hour(Now)
If CurrentHour = 8 Then
    wallpaper = "C:\Wallpapers\day.bmp"
ElseIf CurrentHour = 20 Then
    wallpaper = "C:\Wallpapers\night.bmp"
Else
    WScript.Quit(0)
End If
obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,
UpdatePerUserSystemParameters",1,False
Set obshell = Nothing
share|improve this answer
    
Comprehensive answer, very good. Thanks, John. –  Thomas Oct 19 '09 at 3:28

EDIT: John's answer shows you a full script. My +1 goes to him. This post becomes just another option you may want to look into.

I'm a little rusty on the batch commands so I'm going to give you the highlights:

%TIME:~0,2% - will give you the current hour in your TIME environment variable

So something like this:

IF %TIME:~0,2% == 19 CALL do_Night_Wallpaper.reg
IF %TIME:~0,2% == 07 CALL do_Day_Wallpaper.reg

Would be enough for a script to be placed in your task scheduler and to be set to run every 1 hour. Of course, you may want to adjust the hours to your timezone comfort level. Meanwhile the IF statements are written so that they don't unnecessarily call the reg files. But it means you have to set your task scheduler to run it once every hour at least.

As for the reg files themselves, these are the settings you are after:

  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\ System\Wallpaper
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\ System\WallpaperStyle

The first gets a full path to the wallpaper image. The second is a integer 0 = centered, 1 = tiled, 2 = stretched.

share|improve this answer
1  
And btw, kudos to you on not wanting to add unnecessary programs. My feelings exactly. –  A Dwarf Oct 19 '09 at 2:49
    
Valuable contribution to the question, thanks Dwarf. :) –  Thomas Oct 19 '09 at 3:29
    
Minor nitpick: There is no TIME environment variable. It's a pseudo-variable expanded only by cmd, just like DATE, CD and RANDOM. –  Joey Oct 19 '09 at 5:56

Here is a small VBS program "ready to be used": it gathers all those commands (selection of a random picture file in a directory using the "Randomize" VBS command + refresh the Windows wallpaper with it using "UpdatePerUserSystemParameters" + update the Windows "WallpaperStyle" registry).

And it works with .JPG picture files (not only with .BMP files), which is quite convenient...

The VB script source code is described at http://sites.google.com/site/sharerandomwallpapers/ Thanks.

share|improve this answer

I just try to add minor seasonings to John's script. I try to make the script capable to change wallpaper once every minute according to the time of the day. For example, from 5.00 to 8.59, it changes several wallpapers with morning theme; from 9.00 to 13.59, it changes several wallpapers with midday theme; and so forth. Every theme in this script contains 4 BMP images. Since there are five themes included in the script (morning, midday, afternoon, evening, and night), there will be 20 images required for this script to work.

'creating procedure that changes wallpaper every minute
Sub ChangeWallpaperPerMinute ()
    Set obshell = WScript.CreateObject("Wscript.Shell")
    CurrentHour = Hour(Now)
    'determining the number of images for every time of the day-based theme (set the 'maximum' value according to the number of images for every theme)
    maximum=4
    minimum=1
    'randomizing the images to be changed
    Randomize
    num = Int((maximum-minimum+1)*Rnd+minimum)
    If CurrentHour >= 5 And CurrentHour <= 8 Then
        wallpaper = "morning" & num & ".bmp"
    ElseIf CurrentHour >= 9 And CurrentHour <= 13 Then
        wallpaper = "midday" & num & ".bmp"
    ElseIf CurrentHour >= 14 And CurrentHour <= 16 Then
        wallpaper = "afternoon" & num & ".bmp"
    ElseIf CurrentHour >= 17 And CurrentHour <= 20 Then
        wallpaper = "evening" & num & ".bmp"
    ElseIf CurrentHour >= 21 And CurrentHour <= 23 Then
        wallpaper = "night" & num & ".bmp"
    ElseIf CurrentHour >= 0 And CurrentHour <= 4 Then
        wallpaper = "night" & num & ".bmp"
    Else
        WScript.Quit(0)
    End If
    obshell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper",wallpaper
    obshell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters",1,False
    Set obshell = Nothing
End Sub
'end of procedure creation'
'calling procedure to initiate script's action
ChangeWallpaperPerMinute
'repeating the calling of procedure
do
    WScript.sleep(60 * 1000)
    '60 * 1000 means sixty seconds. If the shifting of wallpapers is expected to occur once every ten seconds, change to 10 * 1000
    'calling procedure
    ChangeWallpaperPerMinute
Loop

To make this script operable, in addition to the script file itself, 20 BMP images are also needed. Four of those images must be named according to the specified nomenclature; that is, for example, morning1.bmp, morning2.bmp, morning3.bmp, and morning4.bmp. The same nomenclature also applies on the naming of 4 midday images, 4 afternoon images, 4 evening images, and 4 night images. Put the VBS file along with the 20 image files in one folder. Because this script repeatedly calls its procedure at specified intervals, when you use scheduled tasks, be sure that you activate this script only at system logon. To deactivate this script, just kill wscript.exe using task manager.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.