[Windows] An example of a batch script that changes the background image of the desktop with a command!Introducing the setting method using the registry

Windows

Hello!Today I will show you how to create a batch file that changes the background image of the desktop with a command.

Basically, I think that most of the background image changes are done manually.
However, it can be changed by using the registry.

Unlike manual, you can easily execute the same settings on other computers, so you can use it when you want to set the same desktop background!

Thing you want to do

Change the background image of the desktop by executing the batch file.

Script example

@echo off

rem ①画像ファイルの設定
set WALLPAPER_IMG=C:\test.bmp

rem ②デスクトップの背景に設定するレジストリ登録
reg add "HKCU\control panel\desktop" /v wallpaper /t REG_SZ /d %WALLPAPER_IMG% /f

rem ③画像の拡大表示設定
reg add "HKCU\control panel\desktop" /v WallPaperStyle /t REG_SZ /d 2 /f

rem ④背景の変更を適用するコマンドを連打する※
rem 1回では反応しないことが多いため複数回挿入しています
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters

* It is a mystery why it does not respond, but you can change it with this for the time being (sweat)

Commentary

I will explain the main processing.

① Image file settings

set WALLPAPER_IMG = C: \ test.bmp

To make it easier to handle the location of the image file you want to set as the desktop background,% WALLPAPER_IMG%In the variableC: \ test.bmp"Is put.

(XNUMX) Registry registration to be set as the desktop background

reg add "HKCU \ control panel \ desktop" / v wallpaper / t REG_SZ / d% WALLPAPER_IMG% / f

here,"Here's the image you want to use as your desktop background!"WindowsI am making a registry change to tell.

You can basically change the registry value to the specified value by doing "reg add ~ / f". (Some access-denied registry values ​​that are relevant to the core of Windows may not be changeable.)

here,"HKCU \ control panel \ desktop"It is in"wallpaperCharacter string type (REG_SZ)ofRegistry valueTo the% WALLPAPER_IMG% = c: \ test.bmp"Is put.

③ Image enlargement display setting

reg add "HKCU \ control panel \ desktop" / v WallPaperStyle / t REG_SZ / d 2 / f

here,"I want the desktop background image to be automatically enlarged or reduced so that there are no gaps at the top and bottom.(Ignore aspect ratio) "WindowsI am making a registry change to tell.

The number "2You can change the display format of the image as follows by changing the part of "".

If you change it to "6"Enlarges / reduces while maintaining the aspect ratio.Margins may be created on either the top, bottom, left, or right.

If you change it to "10"Enlarges / reduces while maintaining the aspect ratio.Instead of having no margins on the top, bottom, left, and right, either the top, bottom, left, or right may extend off the screen.

④ Apply the background change

RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters

"Reflects changes in the desktop background imageIt is a command to make it.

It is not reflected only by executing it onceSometimes, I run it 10 times just in case.

In particular,"user32Called ""Windows API"("user32.dll"Dynamic link library (dll)Is included in the actual file)UpdatePerUserSystemParametersThe function ""rundll32.exeIs running through.

More specifically, "Windows reloads the registry related to user settingsIt is a command.for that reason,"Reflecting changes in the desktop background imageIt will also be in the form of.

When the above command is executed, the background image of the desktop will be changed to the image of "C: \ test.bmp".

Afterword

This time, I introduced the command to change the background image of the desktop.

If you are using a personal computer, you may often just "right-click" the image and press "Set as desktop background".The essence of being able to create a batch file is that it can be incorporated into other processes and that the settings of a large number of PCs can be changed all at once.

If you have a lot of computers, it may be interesting to create a batch file and unify all the designs ♪

I hope it helps you.

Comment

Translate »
I copied the title and URL