|
huiyu
新手上路

积分 14
发帖 5
注册 2008-4-13
状态 离线
|
『楼 主』:
[求助]求一个定时更换桌面背景的批处理!
使用 LLM 解释/回答一下
图片在本地上的,定时可以自己设置
比如说隔三十分钟更换一张桌面背景.
|
|
2008-5-25 13:41 |
|
|
clian76
中级用户
  
积分 363
发帖 162
注册 2007-4-22
状态 离线
|
|
2008-5-26 23:55 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 3 楼』:
有人发过,楼主注意搜索,稍加修改即可。
使用 LLM 解释/回答一下
随机选取图片作为桌面背景的实现
因为自己希望定期从指定目录及其子目录下的JPG文件随机选取一张作为桌面的背景图,而且希望使用居中不拉伸的样式显示,经过多次尝试发现微软提供的BGSWITCH插件未能满足我的要求(每次都会将图片拉伸到满屏),参考论坛上前辈的范例后自己动手写了一个CMD的批处理和一个VBS的脚本,其中VBS的脚本主要是调用WIA的控件将JPG文件转换成BMP文件。
1、setmybg.cmd
@echo off
rem 使用变量延迟扩展的语句
rem setlocal EnableDelayedExpansion
copy nul %~dp0list.txt > nul
for /f "usebackq delims=" %%i in ('dir/a-d/b/s %1') do call set $%%random%%$%%i=$
for /f "tokens=1,2* delims=$=" %%i in ('set $') do echo %%i/%%j >> %~dp0list.txt
for /f "tokens=1,* delims==" %%i in ('set $') do call set %%i=
set /a n=1
rem 使用变量延迟扩展的语句
rem for /f "tokens=1,2* delims=/" %%i in ('sort /R %~dp0list.txt') do if !n! equ 1 ( set bgfile=%%j && set /a n=!n!+1 ) else ( goto end )
for /f "tokens=1,2* delims=/" %%i in ('sort /R %~dp0list.txt') do if %n% equ 1 ( set bgfile=%%j && goto STARTCONVERT )
goto :end
:STARTCONVERT
if not exist %~dp0wallpaper1.bmp goto SETBG
del /f /q %~dp0wallpaper1.bmp
:SETBG
cscript %~dp0convert-bmp.vbs %bgfile% "%~dp0wallpaper1.bmp" > nul
reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%~dp0Wallpaper1.bmp" /f > nul
reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /d "0" /f > nul
reg add "HKCU\Control Panel\Desktop" /v TileWallpaper /d "0" /f > nul
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters > nul
:end
del /f /q %~dp0list.txt
rem 使用变量延迟扩展的语句
rem endlocal
2、convert-bmp.vbs
Dim oImg '图片文件
Dim oIP '图片处理
Set objArgs = WScript.Arguments
sOrgImg = objArgs(0)
sDesImg = objArgs(1)
Set oImg = CreateObject("WIA.ImageFile")
Set oIP = CreateObject("WIA.ImageProcess")
oImg.LoadFile sOrgImg '载入原始图片
oIP.Filters.Add oIP.FilterInfos("Convert").FilterID
oIP.Filters(1).Properties("FormatID").Value = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}" '这里的格式可以自行设定,见附表
'oIP.Filters(1).Properties("Quality").Value = 5 '图片质量
Set oNewImg = oIP.Apply(oImg) '应用
oNewImg.SaveFile sDesImg '保存转换后的图片
使用的时候将两个文件保存在同一个目录,运行setmybg.cmd并提供保存JPG文件的目录作为参数,例如:
setmybg.cmd d:\photo
如果希望选择特定文件名格式的,可以这样:
setmybg.cmd d:\photo\*0709*JPG
希望能帮到有需要的朋友!
|

 |
|
2008-5-27 00:00 |
|
|
gahoo
初级用户
 
积分 45
发帖 19
注册 2007-3-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我也来一个,同样也是参考了以前的帖子,不过借助了外部工具jpg2bmp.exe来转换图片,需要将jpg2bmp.exe放在同一目录下,还是楼上的方便,可惜我不会vbs
@echo off
::下面设置墙纸的路径
set WallPaper_Path=F:\My Documents\My Pictures\cartoon\Lucky WallPaper\
setlocal ENABLEDELAYEDEXPANSION
del "%APPDATA%\Microsoft\Wallpaper1.bmp"
for /f %%i in ('dir "%WallPaper_Path%" /b^|find /C ".jpg"') do set file_num=%%i
set /a skip_line=%random%%%%file_num%
for /f "skip=%skip_line% tokens=*" %%i in ('dir "%WallPaper_Path%*.jpg" /b') do jpg2bmp "%WallPaper_Path%%%i" "%APPDATA%\Microsoft\Wallpaper1.bmp" && call :apply
goto :eof
:apply
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /d "%APPDATA%\Microsoft\Wallpaper1.bmp" /f
RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
exit
jpg2bmp下载
另外想问一下楼上的“%~dp0”和"$%%random%%$%%i=$"中的"$"是什么
Last edited by gahoo on 2008-5-27 at 01:00 AM ]
|
|
2008-5-27 00:16 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 5 楼』:
4楼
使用 LLM 解释/回答一下
for /?
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.
|

 |
|
2008-5-27 00:53 |
|
|
gahoo
初级用户
 
积分 45
发帖 19
注册 2007-3-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
楼上也是夜猫……
明白了,可是“0”的意义呢
“set $%%random%%$%%i=$"中的"$"是什么
|
|
2008-5-27 01:03 |
|
|
zqz0012005
中级用户
  
积分 297
发帖 135
注册 2006-10-21
状态 离线
|
|
2008-5-27 01:11 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
|
2008-5-27 09:12 |
|
|
clian76
中级用户
  
积分 363
发帖 162
注册 2007-4-22
状态 离线
|
|
2008-5-28 13:22 |
|
|
guilinljd
新手上路

积分 14
发帖 7
注册 2008-5-29
状态 离线
|
|
2008-5-30 01:21 |
|