China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 00:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Practical Batch Processing [Part] Changing Desktop Background View 2,381 Replies 7
Original Poster Posted 2008-07-12 17:32 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Take advantage of today's free time, post some practical P

I know this has been posted by someone else, but I have something different.

Mine can set jpg images as background, someone else has posted before that can set jpg images, but it requires DLL file support, but mine doesn't.

It seems to involve the problem that the system automatically converts jpg to bmp format. I hope those with knowledge can study out how the system automatically converts it.

"%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
This is the complete path of the current desktop background.

Test environment: XP SP2

::Copy to change desktop background.bat::
::Drag a BMP format image into P
@echo off
title Change desktop background
cd/d %~dp0
if /i %~x1==.BMP copy %1 "%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
echo Changing desktop background
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
goto :eof
::Copy to change desktop background.bat::
::::::::::::::::::::::::

This has been posted on the forum.

::General change wallpaper.bat::
::The image is in BMP format
::Drag a BMP format image to set it as background.
::Directly double-click to run. If there is a BMP format image in the current directory, it will set the last one as wallpaper
@echo off
title Change wallpaper
setlocal enableDelayedExpansion
set pic=%1
if "!pic!"=="" call :search
if "!pic!"=="" set pic="%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
echo Adding registry items...
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d !pic! /f>nul
reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /d "2" /f>nul
echo Changing desktop background
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
goto :eof
:search
 cd/d "%~dp0"
 for /f "delims=" %%a in ('dir/b *.bmp') do (
  set pic="%~dp0%%a"
 )
 goto :eof
::General change wallpaper.bat::
::::::::::::::::::::::::
::Force change wallpaper.bat::
::Some systems can't succeed
::The image is in BMP or JPG format
::If the image format is JPG, there will be a background color for the desktop icon text (after successfully setting, run the following restore wallpaper once to remove the background color)
::Drag the image to run
::Double-click to run directly, and the last one is set as background
::At the same time, it can prohibit changing wallpaper through desktop properties (software changes cannot be prohibited)
@echo off
title Change wallpaper
setlocal enableDelayedExpansion
set pic=%1
if "!pic!"=="" call :search
if "!pic!"=="" set pic="%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
echo Adding registry items...
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d !pic! /f>nul
reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /d "2" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v Wallpaper /d !pic! /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v WallpaperStyle /d "2" /f>nul
echo Changing desktop background
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
goto :eof
:search
 cd/d "%~dp0"
 for /f "delims=" %%a in ('dir/b *.jpg *.bmp') do (
  set pic="%~dp0%%a"
 )
 goto :eof
::Force change wallpaper.bat::
::::::::::::::::::::::::

::Restore wallpaper.bat::
::Make sure there is "%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
@echo off
title Restore wallpaper
set pic="%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
echo Adding registry items...
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d %pic% /f>nul
reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /d "2" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v Wallpaper /d %pic% /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v WallpaperStyle /d "2" /f>nul
echo Restoring desktop background
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
goto :eof
::Restore wallpaper.bat::
::::::::::::::::::::::::::
Explanation document
Several paths to store desktop background
-------------------------
C:\WINDOWS\Web\Wallpaper
::jpg desktop (there is also Bliss.bmp)
C:\WINDOWS
::bmp desktop
or
::jpg, bmp, gif
-------------------------
Other two positions
-------------------------
The location of the image you specified
::jpg, bmp, gif
"%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
::No special circumstances are the current desktop background
=========================


[ Last edited by wxcute on 2008-7-12 at 08:08 PM ]
┌───────┐
├→学习→实践→┤
└───────┘
Floor 2 Posted 2008-07-12 18:17 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Poor, no one is reading, bumping it myself.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 3 Posted 2008-07-12 19:01 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
::Can also prohibit changing the wallpaper through desktop properties

Personally, I think this is not good.

[ Last edited by HAT on 2008-7-12 at 07:03 PM ]
Floor 4 Posted 2008-07-12 19:10 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Sorry, this was forgotten to be sent.
::Remove Wallpaper Restriction.bat::
@echo off
title Remove Wallpaper Restriction
echo Deleting registry entries...
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v Wallpaper /f>nul
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v WallpaperStyle /f>nul
echo Refreshing
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
goto :eof
::Remove Wallpaper Restriction.bat::
::::::::::::::::::::
┌───────┐
├→学习→实践→┤
└───────┘
Floor 5 Posted 2008-07-12 19:11 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Top~ ^_^
rundll32.exe is really powerful.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 6 Posted 2008-07-12 20:05 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
set pic=%1
if "%pic%"=="" set pic="%userProfile%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp"
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%pic%" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v Wallpaper /d "%pic%" /f>nul
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v Wallpaper /f>nul
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters


把你的两个批处理合并成一个不就行了吗
Floor 7 Posted 2008-07-12 20:11 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
20-year member
UID 59307
Status Offline
Reply to floor 6
One use doesn't work. You need to wait for the system to successfully convert the image, otherwise it won't work.

Also, the system automatically converts jpg to bmp. Has anyone studied this? I can't figure it out. Is it using mspaint or shimgvw.dll?
┌───────┐
├→学习→实践→┤
└───────┘
Floor 8 Posted 2008-07-12 22:38 ·  中国 上海 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
I once used PNG to write to the registry, but the actual boot result might have a half-screen black screen phenomenon when loading the PNG wallpaper. Finally, it was found that all formats were finally converted to BMP format. So it's not troublesome to use BMP for all.
Forum Jump: