2

I am developing a simple application that downloads Desktop Wallpapers from server and saves the images in Wallpaper Downloads. I want to set this directory as my Wallpaper directory as we see in Control Panel\Appearance and Personalization\Personalization\Desktop Background. What i mean is that I want to set each image in this folder as my wallpaper for some specific time as is done in personalization. I have seen codes for setting one image as wallpaper but none for entire folder, is it not possible? Like in Windows Personalization we can browse for the wallpaper folder and then set all the images inside it as our wallpaper which change with some specified amount of time.

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • 1
    Wallpaper is a file, not a folder. There is not such key in the registry. – Endoro Apr 04 '13 at 08:45
  • 1
    Ya i know, what i want to ask is how to set all the images inside a folder as wallpaper using batch script. like in windows personalization they ask to browse a folder and then set all the images inside as wallpaper which change after sometime – Rohan Kandwal Apr 05 '13 at 05:02
  • 2
    Do you want to set a "random" wallpaper from a special folder using batch? – Endoro Apr 05 '13 at 05:05
  • I want to set a folder as wallpaper directory like we browse for folder in Windows Personization and then set the images inside that directory as wallpaper which change after some specific time. You can think of this as we do in Personization but i want to do it using coding. – Rohan Kandwal Apr 05 '13 at 05:08
  • 1
    Basically you can do this with a batch script, but I would prefer AutoIt :) – Endoro Apr 05 '13 at 05:18
  • possible duplicate of [Changing Wallpaper with a batch file, on program close. Possible?](http://stackoverflow.com/questions/7779491/changing-wallpaper-with-a-batch-file-on-program-close-possible), [Windows batch script to switch desktop background](http://stackoverflow.com/q/7041703) – Cody Gray - on strike Apr 05 '13 at 05:20
  • @CodyGray Those two posts are for saving one image as desktop wallpaper while my requirements are different. I have already said that i know how to set one image as wallpaper. – Rohan Kandwal Apr 05 '13 at 05:21
  • @Endoro Can you show me how to do it with script ? I will search AutoIt – Rohan Kandwal Apr 05 '13 at 05:23
  • 1
    Can we assume that the "change picture" option is already enabled? Or do you need to enable that, too? – Cody Gray - on strike Apr 05 '13 at 05:27
  • @CodyGray Sry i didn't understand what you mean by "change picture option " – Rohan Kandwal Apr 05 '13 at 05:36

2 Answers2

2

HKEY_CURRENT_USER\Control Panel\Desktop\WallPaper stores the current wallpaper location.

The easiest way to do this would be to set that registry value to look for a "wallpaper.jpg" then name all of the images in the target folder numerically. Use a simple looping batch file that reads in a number to a batch file, adds one unless it is the number of the last image you have, and write that number back out to the text file. Then change the name of the file with that number to "wallpaper.jpg". Then use task scheduler to have the batch file run at intervals. I have one on my computer that changes the log on wallpaper every time I log on.

Here is a sample batch script.

@echo off
cd C:\Users\kenneth\wallpapers\logon
set n=
set /p n=<numb.txt
move .\background.jpg .\%n%.jpg
if %n% == 30 set n=0
set /a n=%n%+1
move .\%n%.jpg .\background.jpg
ECHO %n%>numb.txt

In this example I have thirty jpg images numbered 1-30. You would have to adjust the value in the sixth line to the number of files you have.

iCodeSometime
  • 1,444
  • 15
  • 30
  • This is for 1 image but i want to set all the images inside a folder as wallpaper using batch script. like in personalization they ask you to browse a folder and then select all the files – Rohan Kandwal Apr 05 '13 at 05:03
  • Your answer is so far the best that i had. Can you provide me the batch files? – Rohan Kandwal Apr 06 '13 at 04:18
  • Isn't there any way through which i can add my directory to the `Personalization` through registry? If i can that loads of complications will be easier like changing the wallpaper when we select `Next Desktop Background`. – Rohan Kandwal Apr 06 '13 at 04:28
  • Nope, sorry there is no registry key that points to an entire folder. I can try to post a sample batch script tomorrow. I'll need to be on a windows machine so I can remind myself of the syntax. – iCodeSometime Apr 06 '13 at 10:42
0

A small improvement on iCodeSometimes' code snippet (@admins: pwese move to comments): Instead of maintaining the max number of pictures in the folder you could just check if the file does exist and if not, reset the counter. Something like

if not exist "%n%.*" set n=0
GuestCoder
  • 71
  • 1
  • 2