[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 换桌面背景(墙纸)命令行工具 WallpaperChanger

此工具用 C# 编写, 运行需要安装 .NET 2.0 以上. 换桌面命令行语法简单, 并且支持 bmp, jpg, gif 等多种格式图片, 而且可以支持 url 图片地址.
语法:
WallpaperChanger.exe [file] [style]
file: 图片地址, 支持 URL
style: 0, 平铺; 1, 居中; 2, 拉伸.
下载 来源于 http://www.sg20.com/wallpaperchanger/
核心原代码在此处可下载
http://www.codeproject.com/dotnet/SettingWallpaperDotNet.asp

附一段将桌面墙纸和 http://cn.bing.com/ 同步的 batch:
  1. @echo off & setlocal enableDelayedExpansion
  2. for /f "delims=:" %%n in ('findstr /n /b /e :text "%~0"') do set jump=%%n
  3. >download.vbs (
  4.   for /f "skip=%jump% usebackq delims=" %%l in ("%~0") do echo %%l
  5. )
  6. <nul set /p=Downloading file: http://cn.bing.com/default.htm ...
  7. wscript download.vbs "http://cn.bing.com/default.htm" cn.bing.htm
  8. echo.&echo Downloading complete.
  9. for /f "skip=2 delims=" %%s in ('find "g_img={url:" cn.bing.htm') do (
  10.   set "sec=%%s"
  11.   for /f "tokens=2 delims='" %%a in ("!sec:*g_img=g_img!") do (
  12.     <nul set /p=Setting new wallpaper: http://cn.bing.com/%%a ...
  13.     WallpaperChanger.exe http://cn.bing.com/%%a 2
  14.   )
  15. )
  16. exit /b
  17. :text
  18. iLocal = LCase(WScript.Arguments(1))
  19. iRemote = LCase(WScript.Arguments(0))
  20. Set xPost = CreateObject("Microsoft.XMLHTTP")
  21. xPost.Open "GET",iRemote,0
  22. xPost.Send()
  23. Set sGet = CreateObject("ADO"&"DB.Stream")
  24. sGet.Mode = 3
  25. sGet.Type = 1
  26. sGet.Open()
  27. strE = xPost.responseBody
  28. sGet.Write strE
  29. sGet.SaveToFile iLocal,2
复制代码
Wallpaper Changer Command Line Utility

Description

WallpaperChanger is a command line utility for changing the wallpaper (desktop background) in Windows. The intent of this program is not to be a standalone wallpaper program (it is too cumbersome to use for that). It is intended to be used as a "helper" utility program for another program or script.

For example, I wrote this program for use with a Java program I was writing to change the desktop wallpaper. I ran into a problem trying to get Java to change the desktop wallpaper. The best way to do it is to use one of the Windows system libraries (dlls). I decided to implement a command line utility program in C# to set a new wallpaper. My Java program executes this external utility program when it sets the wallpaper.

Use
The program takes two arguments: the file (including path) to use as wallpaper, and the style (Tiled, Centered, Stretched)
Syntax is: [file] [style]

        [file] is the complete path to the file
        [style] is an integer (if no style is specified it defaults to Stretched):
        0 for Tiled
        1 for Centered
        2 for Stretched

If the style argument is not specified it will default to Stretched.

The file type can be any of the standard picture types (bmp, jpg, gif, etc.). The program will automatically convert the file to a bmp file (required by windows) and place it within the users temp directory.

The program has a return code - 0 for normal, 1 for error

An error code will be returned if the program had an exception, for example invalid syntax, invalid file name, invalid style type, etc.

Requirements
Because WallpaperChanger is written in C#, it requires the .NET Framework (specifically version 2.0 or later) to be installed.  Version 2 of the framework adds a new method that greatly speeds up some image processing (the wallpaper changer was ridiculously slow before).  If you do not have the .NET Framework installed, you can get it from Windows Update or from the Microsoft website.

The .NET Framework download page can be found here:
http://msdn.microsoft.com/netframework/downloads/updates/default.aspx

Download

Download the WallpaperChanger here

This program is free for use and distribution. It is delivered "as-is". I have tested the program and have been using it without problem in my own wallpaper changing program.

If you have questions or comments, feel free to email: [email=ph-web@sg20.com]ph-web@sg20.com[/email]

The code in the program was based off of the code in a CodeProject article found at:
http://www.codeproject.com/dotnet/SettingWallpaperDotNet.asp

Last Modified: 2007-09-04
1

评分人数

本帖最后由 Hello123World 于 2011-8-2 15:18 编辑

vbs调用bat,bat修改墙纸。
vbs:
  1. CreateObject("Wscript.Shell").run "cmd /c ""E:\My Batch\开机切换墙纸.bat""",vbhide
复制代码
batch:
  1. ::需要外部命令,wallpaperchanger.exe。
  2. @echo off
  3. for /f "delims=" %%i in (c:\wallpaper.txt) do  wallpaperchanger.exe "%%i" & echo %%i>>c:\wallpaper.txt & goto hello
  4. :hello
  5. ::开机则更换墙纸
  6. (for /f "skip=1 delims=" %%i in (c:\wallpaper.txt) do echo %%i)>c:\wallpaper1.txt
  7. del c:\wallpaper.txt
  8. ren c:\wallpaper1.txt wallpaper.txt
  9. ::更新墙纸列表文本
  10. ::这里不能将上面两句简写为move /y ,因为move /y是合并替换。
复制代码

TOP

游戏玩的多了,.net自然也就有了——这点我还好。

TOP

8# tmplinshi
都是外部命令,难道这个就比那个好吗?
Hello123World 发表于 2011-6-22 15:15

IrfanView 不需要 .net 环境。

TOP

本帖最后由 Hello123World 于 2011-6-23 10:22 编辑
  1. ::需要外部命令,wallpaperchanger.exe。
  2. @echo off
  3. for /f "delims=" %%i in (c:\wallpaper.txt) do  wallpaperchanger.exe "%%i" & echo %%i>>c:\wallpaper.txt & goto hello
  4. :hello
  5. ::开机则更换墙纸
  6. (for /f "skip=1 delims=" %%i in (c:\wallpaper.txt) do echo %%i)>c:\wallpaper1.txt
  7. del c:\wallpaper.txt
  8. ren c:\wallpaper1.txt wallpaper.txt
  9. ::墙纸循环完文本行数次后就不再替换了
复制代码
这个bat我已经用上了,开机则换图片,而且wallpaper.txt中的地址会循环使用了。

TOP

8# tmplinshi
都是外部命令,难道这个就比那个好吗?

TOP

TOP

6# tmplinshi
'irfanview' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

TOP

本帖最后由 tmplinshi 于 2011-6-21 19:28 编辑

可以用 IrfanView 设置墙纸。
Example for /wall:

    i_view32.exe c:\test.jpg /wall=0
   
    Open 'c:\test.jpg' and set is as wallpaper (centered).
   
    wall values: 0 (centered), 1 (tiled), 2 (stretched), 3 (stretched-proportional)
   
    i_view32.exe c:\images\*.jpg /random /wall=0 /killmesoftly
   
    i_view32.exe /filelist=c:\mypics.txt /random /wall=0 /killmesoftly
   
    Get random file from the folder/list and set as wallpaper.

TOP

本帖最后由 Hello123World 于 2011-6-21 20:14 编辑

借花献佛,写个自己替换墙纸的bat,我没有更好的算法了,循环一次c:\wallpaper.txt就得更新(有更好算法的朋友不妨写出来分享下)。

必须:wallpaperchanger放在c:\windows\system32文件夹中。
bat放在开机启动项
  1. ::需要外部命令,wallpaperchanger.exe。
  2. @echo off
  3. for /f "delims=" %%i in (c:\wallpaper.txt) do at 14:00 wallpaperchanger.exe "%%i" & goto hello
  4. :hello
  5. ::每周3更换墙纸
  6. (for /f "skip=1 delims=" %%i in (c:\wallpaper.txt) do echo %%i)>c:\wallpaper1.txt
  7. del c:\wallpaper.txt
  8. ren c:\wallpaper1.txt wallpaper.txt
  9. ::墙纸循环完文本行数次后就不再替换了
  10. pause>nul
复制代码

TOP

win7也适用,有兴趣的不妨下着玩。

TOP

本来就想做个定时更换墙纸的bat,一直在找更换墙纸的注册表位置,现在有这个工具直接用就好了,谢谢推荐。

TOP

看看就得,花哨的东西不是XP的作风啊,呵呵!~
寂寞是黑白的,但黑白不是寂寞,是永恒。BAT 需要的不是可能,而是智慧。

TOP

返回列表