7

I'm trying to create a batch file that will change my background when a program closes on Windows 7. I've tried using this, but it doesn't work, even when I log off and log back in:

@echo off
reg /add HKCU\Control Panel\Desktop\WallPaper /v wallpaper /t REG_SZ /d c:\images\wallpaper.bmp
fardjad
  • 20,031
  • 6
  • 53
  • 68
sagev9000
  • 79
  • 1
  • 1
  • 3

1 Answers1

17

There are some errors in your command:

  1. You have added unnecessarry / to add command.
  2. You don't enclose registry key name in quotes (for space escape).
  3. You have specified wrong path (extra WallPaper at the end).

This should do the trick:

reg add "HKCU\Control Panel\Desktop" /v Wallpaper /f /t REG_SZ /d c:\images\wallpaper.bmp

Of course, if the wallpaper path contains spaces you must enclose it in quotes too.

I also added key /f to force overwriting if wallpaper is already set.

Francisco R
  • 4,032
  • 1
  • 22
  • 37
refaim
  • 1,875
  • 1
  • 14
  • 9
  • 1
    It doesn't actually update the screen, any way to force that to happen? – Mr. TA May 11 '16 at 16:58
  • @Mr.TA add this line `reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /f /t REG_SZ /d 10` and run the bat file as administrator - that worked for me. – RozzA Jul 23 '16 at 09:42
  • @Mr.TA try to add this line to your script after the reg add: `RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True` – JPelletier Nov 24 '16 at 14:28
  • Unfortunately, on my PC (Windows 10), it writes the path into the Wallpaper key, but nothing happens - JPG image isn't displayed. Also not with the RUNDLL32.EXE hint to update parameters. Who knows what has changed in W10 ? If I change it via context menu (Personalize), then WallPaper gets populated and the image changes. – Matt Aug 01 '19 at 11:06
  • 1
    **Got the issue:** The script in the answer writes to "Wallpaper" but the value's name actually is **"WallPaper"** - and it is case-sensitive. Now it works! – Matt Aug 01 '19 at 11:11
  • ... but it doesn't always update the image immediately. Does anyone know if there is some more reliable command availabe to force update the picture? I am currently looking [here](https://superuser.com/questions/398605/how-to-force-windows-desktop-background-to-update-or-refresh) ... – Matt Aug 01 '19 at 12:39
  • And it only works reliably when using bmp's! Convert jpg to bmp before using this. – FrankIJ Dec 17 '19 at 09:01
  • LETS GOOOOO, this website gives a PowerShell script that works very amazingly and reliably: https://c-nergy.be/blog/?p=15291 – ZiyadCodes Jun 05 '22 at 11:51
  • To run this powershell script you do this: `os.system(f'powershell.exe -ExecutionPolicy RemoteSigned -file "{scriptPath}"')` – ZiyadCodes Jun 05 '22 at 13:19