标题: [求助]求一个定时更换桌面背景的批处理!
[打印本页]
作者: huiyu
时间: 2008-5-25 13:41
标题: [求助]求一个定时更换桌面背景的批处理!
图片在本地上的,定时可以自己设置
比如说隔三十分钟更换一张桌面背景.
作者: clian76
时间: 2008-5-26 23:55
作个记号,我也想做个批处理的
作者: HAT
时间: 2008-5-27 00:00
标题: 有人发过,楼主注意搜索,稍加修改即可。
随机选取图片作为桌面背景的实现
因为自己希望定期从指定目录及其子目录下的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
希望能帮到有需要的朋友!
作者: gahoo
时间: 2008-5-27 00:16
我也来一个,同样也是参考了以前的帖子,不过借助了外部工具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 ]
作者: HAT
时间: 2008-5-27 00:53
标题: 4楼
for /?
Quote: |
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. |
|
作者: gahoo
时间: 2008-5-27 01:03
楼上也是夜猫……
明白了,可是“0”的意义呢
“set $%%random%%$%%i=$"中的"$"是什么
作者: zqz0012005
时间: 2008-5-27 01:11
%~dp0参见
call /?
$一个普通字符而已,在左边作为变量名的一部分,在右边作为变量的值
[
Last edited by zqz0012005 on 2008-5-27 at 01:12 AM ]
作者: HAT
时间: 2008-5-27 09:12
%0代表批处理文件本身
试试就知道了
@echo off
echo %0
作者: clian76
时间: 2008-5-28 13:22
标题: 已经做好,自动定时更换壁纸批处理版
http://www.cn-dos.net/forum/view ... 0811&sid=65fjFQ
作者: guilinljd
时间: 2008-5-30 01:21
标题: 看了
谢谢