Board logo

标题: [代码合集] [分享]批处理实现windows下自动切换壁纸,支持多种图片格式(原创) [打印本页]

作者: a262615704    时间: 2011-10-14 23:47     标题: [分享]批处理实现windows下自动切换壁纸,支持多种图片格式(原创)

  1. @echo off
  2. color 0a
  3. ::小宝 aaaaa0808 原创于2011-10-14
  4. :获得当前当前路径
  5. echo.
  6. set /p wallpath=请拖入壁纸所在文件夹,并回车:
  7. if %wallpath%*==* set wallpath="%cd%"
  8. if exist %wallpath% (set wallpath=%wallpath:~1,-1%) else exit
  9. ::判断是否存在图片
  10. Dir /b /s "%wallpath%\*.*" |Findstr /i ".bmp .jpg .gif .png" |Find /i /n "." >%temp%\ImgList.tmp
  11. For %%i in (%temp%\ImgList.tmp) do If %%~zi EQU 0 Del %temp%\ImgList.tmp & exit
  12. ::设置更换频率
  13. echo.
  14. set /p tt=请输入更换频率( 秒 ),并回车:
  15. set /a tt=%tt%
  16. ::获得分辨率
  17. for /f "tokens=1,3 eol=H skip=8" %%a in ('reg query hkcc\system\currentcontrolset\control\video /s') do (
  18.   if /i "%%a"=="DefaultSettings.XResolution" (set /a X=%%b) else (
  19.     if /i "%%a"=="DefaultSettings.YResolution" set /a Y=%%b
  20.   )
  21. )
  22. echo.
  23. echo 当前分辨率: %X% * %Y%
  24. ::注册图片转换组件
  25. If not exist %SystemRoot%\system32\WIAAut.dll (
  26. Copy /y %开机共享目录%\WIAAut.dll %SystemRoot%\system32
  27. RegSvr32 /s WIAAut.dll
  28. )
  29. ::生成VBS脚本
  30. set "ImgVbs=%temp%\ImgVbs.vbs"
  31. echo Dim Fso,ImgFile,BmpFile,Img,IP >"%ImgVbs%"
  32. echo ImgFile=WScript.Arguments(0)>>"%ImgVbs%"
  33. echo BmpFile="%USERPROFILE%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp">>"%ImgVbs%"
  34. echo Set Fso = CreateObject("Scripting.FileSystemObject")>>"%ImgVbs%"
  35. echo If Fso.FileExists(BmpFile) Then Fso.DeleteFile(BmpFile)>>"%ImgVbs%"
  36. echo Set Img = CreateObject("WIA.ImageFile")>>"%ImgVbs%"
  37. echo Set IP = CreateObject("WIA.ImageProcess")>>"%ImgVbs%"
  38. echo Img.LoadFile ImgFile>>"%ImgVbs%"
  39. echo IP.Filters.Add IP.FilterInfos("Convert").FilterID>>"%ImgVbs%"
  40. echo IP.Filters(1).Properties("FormatID").Value = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}" >>"%ImgVbs%"
  41. echo IP.Filters(1).Properties("Quality").Value =9 >>"%ImgVbs%"
  42. echo Set Img = IP.Apply(Img)>>"%ImgVbs%"
  43. echo Img.SaveFile BmpFile>>"%ImgVbs%"
  44. echo Set Img=Nothing>>"%ImgVbs%"
  45. echo Set IP=Nothing>>"%ImgVbs%"
  46. echo Set Fso=Nothing>>"%ImgVbs%"
  47. echo wscript.quit>>"%ImgVbs%"
  48. ::随机查找图片
  49. For /f "delims=[]" %%i in (%temp%\ImgList.tmp) do Set "Num1=%%i"
  50. If %Num1% LSS 10 (Set "Num3=1") Else (if %Num1% LSS 100 (Set "Num3=2") Else Set "Num3=3")
  51. ::----------循环开始---------
  52. echo.
  53. echo 每%tt%秒后更新一次壁纸...
  54. goto loop
  55. :loop
  56. ::获得新地址
  57. Call Set "Num2=%%random:~-%Num3%%%"
  58. If %Num2% GTR %Num1% Goto loop
  59. For /f "tokens=* delims=0" %%i in ("%Num2%") do Set "Num2=%%i"
  60. If "%Num2%!"=="!" Set "Num2=%Num1%"
  61. Set ImgPath=
  62. For /f "tokens=1* delims=[]" %%i in (%temp%\ImgList.tmp) do If /i %%i==%Num2% Set "ImgPath=%%j"
  63. ::生成新壁纸
  64. Start /wait WScript.exe "%ImgVbs%" "%ImgPath%"
  65. ::刷新桌面
  66. Reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "%USERPROFILE%\Local Settings\Application Data\Microsoft\Wallpaper1.bmp" /f >nul
  67. Reg add "HKCU\Control Panel\Desktop" /v TileWallpaper /d "0" /f >nul
  68. Reg add "HKCU\Control Panel\Desktop" /v WallpaperStyle /d "0" /f >nul
  69. Reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v ListviewShadow /d "1" /f >nul
  70. RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
  71. ping 127.1 /n %tt% >nul
  72. goto loop
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2