此工具用 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:- @echo off & setlocal enableDelayedExpansion
- for /f "delims=:" %%n in ('findstr /n /b /e :text "%~0"') do set jump=%%n
- >download.vbs (
- for /f "skip=%jump% usebackq delims=" %%l in ("%~0") do echo %%l
- )
- <nul set /p=Downloading file: http://cn.bing.com/default.htm ...
- wscript download.vbs "http://cn.bing.com/default.htm" cn.bing.htm
- echo.&echo Downloading complete.
- for /f "skip=2 delims=" %%s in ('find "g_img={url:" cn.bing.htm') do (
- set "sec=%%s"
- for /f "tokens=2 delims='" %%a in ("!sec:*g_img=g_img!") do (
- <nul set /p=Setting new wallpaper: http://cn.bing.com/%%a ...
- WallpaperChanger.exe http://cn.bing.com/%%a 2
- )
- )
- exit /b
-
- :text
- iLocal = LCase(WScript.Arguments(1))
- iRemote = LCase(WScript.Arguments(0))
- Set xPost = CreateObject("Microsoft.XMLHTTP")
- xPost.Open "GET",iRemote,0
- xPost.Send()
- Set sGet = CreateObject("ADO"&"DB.Stream")
- sGet.Mode = 3
- sGet.Type = 1
- sGet.Open()
- strE = xPost.responseBody
- sGet.Write strE
- 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 |