How to change wallpaper using batch

2019-05-11 12:21发布

问题:

I need to make a batch file that changes the wallpaper to a picture that is in the same location as the bat file I currently have this code:

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

the problem with this is that it the pictures need to be in the folder c:\images\ and I need it to be in the same place as the bat file. does any one know how I could do it.

回答1:

You can use %~dp0wallpaper.bmp

%~dp0 returns the full path of the batch file that is being executed with a backslash at end.

You probably might want to enclose the filename in double quotes in case the batch file's directory contains spaces: "%~dp0wallpaper.bmp"