Changing Wallpaper with a batch file, on program close. Possible? [closed]
Asked Answered
W

1

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
Wachtel answered 15/10, 2011 at 17:39 Comment(1)
Are you also opening the program you want to monitor via the batch script?Subsidiary
S
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.

Sundew answered 16/10, 2011 at 10:0 Comment(9)
It doesn't actually update the screen, any way to force that to happen?Backache
@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.Trimolecular
@Mr.TA try to add this line to your script after the reg add: RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,TrueDeclinature
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.Tini
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!Tini
... 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 ...Tini
And it only works reliably when using bmp's! Convert jpg to bmp before using this.Nievelt
LETS GOOOOO, this website gives a PowerShell script that works very amazingly and reliably: c-nergy.be/blog/?p=15291Giorgi
To run this powershell script you do this: os.system(f'powershell.exe -ExecutionPolicy RemoteSigned -file "{scriptPath}"')Giorgi

© 2022 - 2024 — McMap. All rights reserved.