Search code examples
windowscommand-linebatch-filedesktop-applicationwallpaper

Set Wallpaper directory using batch file


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.


Solution

  • 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.