Google Answers Logo
View Question
Q: Setting the desktop background in WinXP through the command prompt ( No Answer,   3 Comments )
Subject: Setting the desktop background in WinXP through the command prompt
Category: Computers > Graphics
Asked by: malriem-ga
List Price: $2.00
Posted: 22 Apr 2005 07:18 PDT
Expires: 22 May 2005 07:18 PDT
Question ID: 512662
I want to set my background (on a Win XP machine) through the command
prompt (ie mspaint.exe /b c:\temp\mypic.bmp) would set mypic.bmp as my
current background using mspaint.  I also want to do it without any
third party software or code, only using standard windows programs.
There is no answer at this time.

Subject: Re: Setting the desktop background in WinXP through the command prompt
From: vladimir-ga on 22 Apr 2005 16:00 PDT
Create a file with the following contents:


[HKEY_CURRENT_USER\Control Panel\Desktop]

And save it under some name, say wallpaper.reg.

Then execute the following command:

regedit /s wallpaper.reg

The creation of the file can be easily automated with simple commands
like echo "xxx" >> filename.

Hope this helps.
Subject: Re: Setting the desktop background in WinXP through the command prompt
From: svancouw-ga on 28 Apr 2005 10:33 PDT
Here is a much safer way to do it. The default location and name for
the background image is c:\Documents and Settings\[username]\Local
Settings\Application Data\Microsoft\Wallpaper1.bmp.

The only that I need to know is what you intend on using it for. Will
it be regularly changing with different filenames? Do you want it to
run automatically?

The bast way to do it is manually, as setting up a script with
variables is a bit of a pain. Type the following:

Copy /Y "[path and name of the image you want to use]" "c:\Documents
and Settings\[username]\Local Settings\Application Data\Microsoft\"

This copies a file (should already be a .bmp) to the directory where
windows stores the desktop image, and overwrites the old one without
requiring a prompt. The name of the file is seperate so that the
original file will be renamed when it arrives at the destination

If you want an automatic scripts with variables, you need to ask for more than $2.
Subject: Re: Setting the desktop background in WinXP through the command prompt
From: 888mark-ga on 10 Dec 2005 13:00 PST
There is no Microsoft-supplied program to do this from the command
line.  And unfortunately neither of the answers above will work
either.  They change the the entry in the Registry but the background
will not change until the next time you log in.

The only way to do this reliably is with a program that calls
SystemParametersInfo with function code SPI_SETDESKWALLPAPER and a
string with the pathname of the file you wish to use as the new
background.  I have written a program that sets the desktop background
to the filename given on the command line (if that fails for some
reason, the old background is put back).  It uses only documented
interfaces and makes the call in such a way that the registry is not

Here is the code.  I had to declare SPI_GETDESKWALLPAPER directly
because for some reason my version of the SDK doesn't have it defined,
even though it's documented!

#include <windows.h>
#include <stdio.h>


void printusage(char *program)


	fprintf(stderr, "Usage:  %s background-file.bmp\n", program);
	fprintf(stderr, "   Changes desktop background to background-file\n");


int main(int argc, char *argp[])


	DWORD dResult;
	BOOL result;
	char oldWallPaper[255];

	if (argc != 2) {
		return 1;

	result = SystemParametersInfo(

	fprintf(stderr, "Current desktop background is %s\n", oldWallPaper);

	result = SystemParametersInfo(

	if (!result) {
		dResult = GetLastError();
		fprintf(stderr, "Attempt to set new desktop background failed; code
%d\n", dResult);
		fprintf(stderr, "Will restore prior setting (%s)\n", oldWallPaper);

		result = SystemParametersInfo(

		return 2;

	fprintf(stderr, "Desktop background changed to %s\n", argp[1]);
	return 0;


Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy