Wallpaper Changer Command Line Utility

.NET Add comments

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 executed this external utility program when it set the wallpaper.

This utility works fine with Windows XP, Vista, and Windows 7.

Use

The program takes two arguments: the file (including path) to use as wallpaper, and the style (Tiled, Centered, Stretched). Instead of a file, a directory can also be specified in which case a random image from the directory will be set as the wallpaper.

Syntax is: [file|directory] [style]

	[file] is the complete path to the file
	[directory] is the complete path to a directory containing image files
	  a random image from the directory will be set as the background
	[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. If you do not have the .NET Framework installed, you can get it from Windows Update or from the Microsoft website.

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 used it without problem in my own wallpaper changing program.

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

5 Responses to “Wallpaper Changer Command Line Utility”

  1. Dmitry Says:

    Thanks for awesome utility dawg! Been looking for something like that for ages.

  2. ddf Says:

    I cant make it work as scheduled task

  3. phil Says:

    You can set it as a scheduled task in windows, but it is annoying how command line programs pop up a little program window when run from the scheduler.

    The best solution for keeping the window hidden seems to be using a VB script. Check out this page for more info http://gallery.technet.microsoft.com/ScriptCenter/8bbed56f-a7aa-491f-a296-687dd96098a3/

    I put that code into a file with a .vbs extension (this makes it a vb script file which windows can execute). For the main line I used this:

    errReturn = objProcess.Create(”C:\wallpapers\WallpaperChanger.exe c:\wallpapers”, null, objConfig, intProcessID)

    You have to include the command line argument which would work ok if you are using a directory containing wallpapers. When I used the vbs file with Windows task scheduler it remained hidden and did not flash any window on the screen.

  4. Justin Swanson Says:

    Just wanted to stop by and say thanks! I had a Java Program in mind to change wallpapers and I stumbled upon your article. Thanks for sharing your work, as it is going to make my life much easier. 8)

  5. phong Says:

    This is the one that I have been looking for. But one thing…. I personaly set my temp folder on a RAM disk volume so that the temp folder is all cleared at boot time. Could you add an option to locate the converted bmp file to another place, or make an alternative build?

Leave a Reply

© Phillip Hansen | Original theme by N.Design Studio
Entries RSS Comments RSS Log in