up vote 4 down vote favorite
2
share [g+] share [fb]

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.

link|improve this question
3  
Upgrade to Windows 7. This is built in. – Steve Rowe Oct 19 '09 at 2:14
1  
@Steve Rowe: -1 – Thomas Oct 19 '09 at 3:31
feedback

3 Answers

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
link|improve this answer
Comprehensive answer, very good. Thanks, John. – Thomas Oct 19 '09 at 3:28
feedback

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.

link|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
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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