Wallpaper changer batch file or script help

January 6, 2011 at 16:20:34
Specs: Windows XP
I change my wallpaper a lot, and every time I do so I have to change its position to center or stretch via display properties. Surely a batch or VBScript file could perform this simple task? That way I could assign a shortcut key to it and save a lot of time.

See More: Wallpaper changer batch file or script help

Report •

#1
January 7, 2011 at 01:06:52
Syrphian, suspect you'll get more and more knowledgeable answers in the programming forum @:
http://www.computing.net/forum/prog...
HTH.
Ed in Texas.

Report •

#2
January 7, 2011 at 11:45:34
Out of curiosity, are you downloading wallpapers that match your screen size?

We all live on a ball.


Report •

#3
January 7, 2011 at 14:18:27
Ed in Texas, I created a thread there as well.

Derek, sometimes, sometimes not. Don't think me rude, but I hardly see the relevance in this.


Report •

Related Solutions

#4
January 7, 2011 at 15:19:41
I was just trying to understand why you have to "change its position to center or stretch via display properties" at all. I change my wallpaper from time to time but it only looks wrong if I use wallpaper that doesn't match the screen size.

Perhaps it is just a personal requirement to make alterations to what is finally seen, or to allow you to use a wide range of different size wallpapers. Presumably we are talking about the desktop background, or is it something else?

We all live on a ball.


Report •

#5
January 7, 2011 at 15:47:52
Your understanding of the matter is of little consequence, but if you feel you must know, far be it from me to deny your thirst for knowledge satisfaction.

Yes, we are talking about the desktop background. When I download a wallpaper from a website, oftentimes the image sizes provided are inconsistent with my screen resolution (1024 by 768), in which case I resize the image from, say, 1920 by 1200 to 1024 by 640, center it, and it looks great.

Example of such a wallpaper

http://i56.tinypic.com/1zydn2x.png


Report •

#6
January 7, 2011 at 16:13:26
I don't think there is any need for the asides. It often helps to know the background because it can make a difference to working out the best way forward.

Most graphical changes are made in the registry. There are registry snapshot programs around which could pick up the "before and after" changes necessary so they could be put into a reg files.

Another possibility is to use something like AutoHotkey which can follow either mouse clicks or sometimes (better) their keyboard equivalents. This would save going via the more time consuming normal route. I will look and see how friendly CP - Center or Stretch are likely to be to these possibilities. I might fail so you will need to be tolerant.

EDIT:
I've just started looking but I'm in the UK time zone so I won't be able to continue much further tonight. What might help a little in the meantime is to make a shortcut on the desktop with this target:
control desk.cpl,,@desktop
Call it Display Desktop. It will allow you to at least get to the right place in one step.

There are problems with using AutoHotkey for this process so I'll see if there is any scope for a reg file solution.

We all live on a ball.


Report •

#7
January 7, 2011 at 17:01:45
I've worked this out using XP SP3 but by all means check it in regedit manually before you start:

Paste what follows between the two lines below into NotePad and save it as:
Center.reg
===============================================
Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-21-602162358-1336601894-725345543-1005\Control Panel\Desktop]
"WallpaperStyle"="0"

===============================================


Now Paste what follows between the next pair of lines into NotePad and save
this one as:
Stretch.reg
===============================================
Windows Registry Editor Version 5.00

[HKEY_USERS\S-1-5-21-602162358-1336601894-725345543-1005\Control Panel\Desktop]
"WallpaperStyle"="2"

===============================================

Note that you must have either one or two (max) line feeds at the bottom below each Wallpaper Style entry.

You should then be able to switch between Center and Stretch by double clicking the appropriate file. To avoid the prompts you can run each of these via a batch file with /s in it. If you need any assistance with this I'll be back tommorow as its gone 1.15am now and I'm off to bed.

There is probably a way of toggling these registry changes via a shortcut but that could take a bit more thought - at least it points you in the right direction. Let us know how you get on.

We all live on a ball.


Report •

#8
January 7, 2011 at 20:26:11
Quite helpful. Thanks!

When I open the registry file, it indeed changes the wallpaper position, but in order to make that change go into effect, I have to go to the display properties and press "OK", so I made a batch file to run the .reg and added "control desk.cpl,,@desktop", so all I have to do is press the shortcut key I assigned it and hit enter. As miraculously convenient as this already is, is there perhaps a way I can tell the batch file to press "OK" in the display properties upon opening it? Jeez, how lazy can I get?


Report •

#9
January 8, 2011 at 10:01:24
They key combination Alt+A (Apply) should do this, which means there is scope, after all, for using the little freebie program AutoHotkey. The reason I rejected it originally is because you would have to use mouse click memorizing. The problem with the latter is it is only reliable (to my knowledge) if you can be certain the Window is always in the exact same place on the screen. I've not found any Windows OS too reliable in that respect.
[I don't know a way of incorporating Alt+A into a batch file - someone else might].

So, with AutoHotkey (very useful to have available anyway) and a combination or reg and/or batch files built into the script you should be able to achieve your objective. I can help with AutoHotkey if necessary but it sounds like you are plenty capable enough to pull this together.

You might also consider toggling from a single icon. With two stored shortcuts you could make the batch file replace with the opposite desktop shorcut file each time it is used. Alternatively you could simply have a desktop folder that contains both batch files. Either way you would then only have to clutter your desktop with one icon.

I'm no expert on VBS script or programming proper. Now your post has been moved to the Programming forum it might be worth keeping an eye on this post to see if anyone joins us with a more elegant or neater solution.

We all live on a ball.


Report •

#10
January 8, 2011 at 10:58:29
The more elegant/neater solution would be to use SystemParametersInfo() to set the desktop wallpaper and announce the change, but this would require use of a language that can interface with the Win32 API.

How To Ask Questions The Smart Way


Report •

#11
January 8, 2011 at 15:25:48
"[I don't know a way of incorporating Alt+A into a batch file - someone else might]."

Download NirCMD: http://www.nirsoft.net/utils/nircmd...

Unzip nircmd into your Windows directory (or Windows\System32)

Then do this:

nircmd.exe sendkey 0x12 down
nircmd.exe sendkey a press
nircmd.exe sendkey 0x12 up

For more nircmd sendkey help: http://nircmd.nirsoft.net/sendkey.html
For more Virtual Key Codes: http://msdn.microsoft.com/enus/library/ms927178.aspx

"is there perhaps a way I can tell the batch file to press "OK" in the display properties upon opening it?"

::SCRIPT.bat

@echo off
start control desk.cpl,,@desktop
nircmd.exe wait 3000
nircmd.exe dlg "" "" click ok
exit

You will need nircmd for this, download link above.

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#12
January 8, 2011 at 16:21:50
My prayers have been answered. Derek's registry edit coupled with MUs' nifty nircmd works wonders. Good job, fellas, and danke much.


Report •

#13
March 11, 2011 at 15:59:02
I'm guessin u would have it all sorted by now but I think this would have been an easier way....
Just copy and paste this into notepad and rename it as a .bat file after you have edited it.

echo off
:: Configure Wallpaper
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\Windows\WEB\wallpaper\bliss.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
:: Make the changes effective immediately
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters


This will load your picture, set it as your background, stretch it then apply it immediately as your wallpaper. In the first REG ADD key, you will need to change the directory and filename of your wallpaper picture. If u only want to stretch your currently displayed wallpaper, you can delete the first reg entry. If you want to center your wallpaper instead of stretching it, just change in the second REG ADD key the last number (which is currently 2) to a 0 and change the last number in the 3rd REG ADD key (currently 0) to a 2.
Then just double klik on the .bat you have saved 2 execute or use scheduler to automate it... Too easy hey????


Report •

#14
March 13, 2011 at 05:39:08
Hello Mu.

"[I don't know a way of incorporating Alt+A into a batch file - someone else might]."
By using a little bit VBscript it can be done from Batch file.. check out below example.

=====================================================
@echo off >mu.txt
echo Set WshShell = WScript.CreateObject("WScript.Shell") >temp.vbs
echo wshshell.run "notepad MU.txt" >>temp.vbs
echo wscript.sleep 500 >>temp.vbs
echo wshshell.AppActivate "MU.txt - notepad" >>temp.vbs
echo wshshell.sendkeys "Hello MU!">>temp.vbs
echo wshshell.sendkeys "{enter}">>temp.vbs
echo wscript.sleep 10 >>temp.vbs
echo wshshell.sendkeys "I am sending Alt + A now ">>temp.vbs
echo wscript.sleep 1000 >>temp.vbs
echo wshshell.sendkeys "{enter}">>temp.vbs
echo wshshell.sendkeys "%%FA" >>temp.vbs
cscript /nologo temp.vbs
===========================================================

each line are self explanatoriry. I beleive you used VBscript in one of your post as well recently.

Subhash Chandra.


Report •

#15
March 13, 2011 at 12:02:27
"I beleive you used VBscript in one of your post as well recently."

I dont know VBS-scripting LOL :X

Happy is ONE who says I am an OttoMAN.


Report •

Ask Question