Jump to content

batch file to change wallpaper?


Recommended Posts

Posted

Hey guys and girls.

Ehmm well im just wondering if there is possible/any easy way to make a batch file to change my wallpaper. or would i need to actually learn a computer language.

As you probally understand by now, i dont really know mutch about that.

i want to make a file that i just press to change wallpapers, the walls i will put in a folder like C:Wallpapers

Or should i just use something like the wallpaper changer in an app a day (maybe some of you have tried it, i think an app a day was on the show a while back)

As usuall, any help/suggestions etc is appriciated :)

Posted

Easiest way is probably to save all your wallpapers as BMPs (since that's all windows can use as wallpapers any way). Set the wall paper as one of the BMPs, then just use a script to change the names of the files. Not certain on when windows will desied to re-read the file for changes, but it will at least take a desktop refresh.

Posted
Easiest way is probably to save all your wallpapers as BMPs (since that's all windows can use as wallpapers any way).

WTF? It's been able to use JPGs (and probably other formats) for nearly a decade...!

Posted
WTF? It's been able to use JPGs (and probably other formats) for nearly a decade...!

That's exacly what Microsoft wants you to think (poor moonlit, blind to the truth ;)).

What windows does when you tell it to use a jpg, png, gif (or what ever) is it converts it to a bitmap in the background and then uses that bitmap as the background not the original file. The result is if you replace a jpg that's been set as the wallpaper with another jpg of the same name, the wallpaper won't change until windows decides it's time to convert it to a bmp again.

Changing it to a bmp your self cut's out that crap and should (hopefully) make the wallpaper reload on desktop refresh, if nothing else it will certainly load faster upon initial desktop load.

Posted
WTF? It's been able to use JPGs (and probably other formats) for nearly a decade...!

If you look at the reg key: HKEY_CURRENT_USERControl PanelDesktop

you will notice that there is a string called "ConvertedWallpaper" where this is the actual jpeg file your using. It then CONVERTS it to a bitmap, which shows up in a string below as "Wallpaper" and "OriginalWallpaper" is the previous set wallpaper. You can copy the string value and paste it into Start/RUN to see the OriginalWallpaper or Wallpaper image from each string.

I am not sure how it is doing the gif animations yet though, but I am looking into that.

I can make the background change and update using visual basic 6, but to do it all in dos batch scripting and vbs is a bit more challenging. I have had little experience with VBS and WScript host files. Its similar to VB6, but foreign to me so far. Not used to all the CreateObject("Scripting.FileSystemObject") stuff, but I am working on it.

I have the basics for the scripts down, and even a reg file that will set a new wallpaper, so that on reboot, it will refresh to the new wallpapwer, but to have it do it without rebooting is a bit more challenging.

Posted

Ok, I have worked out a basic batch and vbs script that will set a random bmp file for next reboot. The problem I am having is that it won't add jpegs or gifs at this time, so if you want to use it or modify it, you would need to add all your bitmaps in one folder and point the scripts to that folder.

http://www.twistedpairrecords.com/randomwallpaper.rar

The code is not perfect, but it does the job, and since I only spent a little time messing with it, I am sure someone can do it in less lines of code. I am no programmer, so what you see is a n00bs work at best when it comes to scripting. I am better in VB6, but since the question was for batch scripting, I decided to give it a shot.

I just want to point out that while most of this was done from my head (concept anyways) most of the vbs code was found online using Google. So I have to say what many people on the forums have said, check GOOGLE first and then come here with the questions. I had no knowledge of how to do this before looking at other works first, so take the time to read and experiment. :idea:

Oh, and if you have VMWare or similar, try out your testing your work there first. It makes for a much safer day when things go wrong with your scripts. :wink:

Posted

I have added comments to the batch script for people running windows 98. I noticed that ir throws an error when running because 98 uses "cscript somefile.vbs" instead of "call somefile.vbs". Also, 98 used REGEDIT4, not the "Windows Registry Editor Version 5.00" for reg files.

Be sure to point to the path where your bmp's are as well. Windows 95/98 keep them in the "c:windows" folder, unlike my script which uses "C:WINDOWSWebWallpaper" by default for XP.

Posted

Thanks alot guys, appriciated :)

Hmm seems like i should learn myself a little more then the just absolute basics. Atleast since usefull this i want keep comming more and more. and googling around for everything opensource is kinda well time consuming, when i could use the time to actually write it myself.

Posted
Tried re-jigging the code?

How can I rearrange the code? Have you looked at it? I'm open to suggestions. Like I said, it's not perfect, but it works for basic bitmaps.

I can make it load the jpegs, but they will not show up on reboot. The problem woul dbe that in order for the jpeg to show up, you would need to click properties on the desktop, then the deskop tab, and it "pre-delects" the jpeg because it is being pointed to in the registry. If you then hit ok it loads the ne wimage, but this defeats the purpose, because you could just have loaded from the menu to begin with only you would have to scrool through to find the image.

In vb6, it can set the image right away, and it refreshes the background, but I wanted to challenge myself in dos and vbscript. Given time, I am sure I could rejigg the code, but it would still need to find a way to load jpegs and gifs, which I think would require more api calls from something like a compiled program, similar to "app a day" wallpaper changer. His goes a step further and not only changes the wallpaper, but gets the images form the web, which I think would require some perl or web scripting combined with the dos batch and vbs files I provided. That is a bit over my head for the scope of what PureZero asked for.

Posted

hmm ive got the code for this in C (my re-hashed version of anappadays google image changer) and i also belive that i have started the same project in VB6 but had issues with it (oh noes VB has failed me)

-edit-

oh wow, i just made it in VB.Net, pretty much the method used was to read the app root for all images, list them, as the timer hit 0 it would take the next item in the list and load it into an image contaner, then easly converted it into BMP with the lines:

pic.Image.Save(imagePath, ImageFormat.Bmp)

then used the API for System Parameters Info, to set the new wallpaper.

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)

Posted
oh wow, i just made it in VB.Net, pretty much the method used was to read the app root for all images, list them, as the timer hit 0 it would take the next item in the list and load it into an image contaner, then easly converted it into BMP with the lines:

pic.Image.Save(imagePath, ImageFormat.Bmp)

then used the API for System Parameters Info, to set the new wallpaper.

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, SPIF_UPDATEINIFILE)

Is there a way to port it to VBS? So someone without .net can run this with the basics installed by default in windows. I am seeing that this can probably be done in such a way that there is no need for a compiled app, but just pure scripting. There is a command for SPI_SETDESKWALLPAPER in vb6 as well, but you have to add some things to a module to get it to auto update the desktop and he could have just downloaded the one for "appaday" if he wanted an exe file. I made one in vb6 a while ago on my old 98 box, but I don't have the source code lying around.

I'm not too good with vbs or wscript/cscript, but I am sure there is a way to do api calls in there to do all of this for us.

It would probably come in handy too, since most windows pc's have cscript/wscript installed allready.

Posted

hmm tonight when i get home ill install VB6 and have a look, as for VBs im not so sure, it uses a set of API's and the conversion from JPG, PNG, GIF -> Bitmap is also a major issue.

As for VB6, im rather sure i can doit, though i need to install it again, if ur still using it i suggest download a copy of VB.net express (free from MSDN)

Posted
hmm tonight when i get home ill install VB6 and have a look, as for VBs im not so sure, it uses a set of API's and the conversion from JPG, PNG, GIF -> Bitmap is also a major issue.

As for VB6, im rather sure i can doit, though i need to install it again, if ur still using it i suggest download a copy of VB.net express (free from MSDN)

Tried VB Express, but I did not like it much. VB6 just seems so intuitive and was easy to learn, but then again, I am not a C+, perl, or php guy and I know nothing of the windows api internals. I usually set out to make something I need, and then make it in VB6. Thats how I learned. Like most people on here say "check google" I pretty much am self taught because of Google, and when I see someone ask a question, I sually try to do what they ask, not to help them or do it for the, but because, hey, I'd like to know how to do that as well.

vbscript or VBS whatever you want to call it provides a bit of a challenge, because I can see in VB6 where you call in these libraries and api calls, but in VBS I think I would need to learn more about the CSCRIPT and WSCRIPT functions to execute the same thing without a compiled program.

Maybe I learned everythign backwards? Most people start with Basic, then scripting, batch, etc, then move on to programming and compiling with things like c++, Visual Basic, perl, etc. I started with HTML and Visual Basic, so I am not familiar with any real hands on material and I think I kinda shot my self in the foot for starting with something after the basics, if you catch my meaning. There are 10 year olds running Linux at home and making all kinds of sh*t and I am still trying to figure out how the hell half of my computer works And, I work in the IT department where I work (10 years and counting) and I still only know what I have taught myself. Wish they had the internet at my school when I was in high school(graduated in '92). We had green screen all in one keyboard and monitors to learn basic. I never understood it then, and I think that is part of the problem I am having now.

Posted
i think you can use nircmd to refresh the desktop...

or just use a html file as the background with a active desktop and use a meta-refresh to cycle through the pages

Active Desktop just eats memory and makes the icons not show up properly. Also, having anything html on the desktop just to see the wallpaper kind of defeats the purpose of just changing the wallpaper.

Once I get the jpeg part working, everything is finished. As it is now the program works, but only cycles the bmp's.

Posted

This is the script that I use it will apply a random wallpaper (only bitmaps) each time you run it.

' Random Wallpaper Changer

'the only files allowed in wallpaper directory are bmp's

option explicit

Dim oShell, fold, fileset, fileCount

Dim counter, fileToPick, randomFile, fso, file, sWallPaper

Set oShell = WScript.CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")

'change "getFolder" to your path

Set fold = fso.GetFolder("C:Wallpaper")

Set fileset = fold.files

fileCount = fileset.count

if fileCount > 0 then

'random file from folder

counter = 1

randomize

fileToPick = clng((rnd * fileCount) + 0.5)

for each file in fileset

if counter < fileToPick then

counter = counter + 1

else

randomFile = file.path

exit for

end if

next

else

response.write "Wallpaper directory is empty."

end if

set fileset = nothing

set fold = nothing

set fso = nothing

sWallPaper = randomFile

' update in registry

oShell.RegWrite "HKCUControl PanelDesktopWallpaper", sWallPaper

oShell.RegWrite "HKCUControl PanelDesktopTileWallpaper", 0 'Do not tile wallpaper

oShell.RegWrite "HKCUControl PanelDesktopWallpaperStyle", 0 'Center wallpaper

' let the system know about the change

oShell.Run _

"%windir%System32RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _

1, True

Posted
' let the system know about the change

oShell.Run _

"%windir%System32RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _

1, True

Does this update it on reboot, or while still active? because it does not update it on mine untill I reboot.

Posted
' let the system know about the change

oShell.Run _

"%windir%System32RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", _

1, True

Does this update it on reboot, or while still active? because it does not update it on mine untill I reboot.

It should not need a reboot. I've tried it on 2 2000 machines and 3 or 4 xp systems without any problems, not sure why it's not working for you?

Posted

I was woundering if I didn't want to use randomly changeing desktop but just change it with a jpg or gif where do I copy my jpg to? this would make a good switchblade payload new corp desktop img or gag on friend at lan party ;)

Posted

Ok. I see where I messed it up. I got it working now. Thanks for that peice of code JohnArtisan for the desktop refresh. Your script works, but it will not run on win98. Also went and tested it and made the appropiate changes for the DLL locations in 98, and it gets a "missing entry:UpdatePerUserSystemParameters" and it crashes Rundll32.exe

I like your code better than what I came up with though, it will only work on NT systems. I tried looking through the user32.dll and couldnt find any hooks for anything other than initializing the user interface, but that seems to just crash rundll as well and doesnt work. Any suggestions on how to get it to run under 98?

Posted
I was woundering if I didn't want to use randomly changeing desktop but just change it with a jpg or gif where do I copy my jpg to? this would make a good switchblade payload new corp desktop img or gag on friend at lan party ;)

Right now the way this works it will not chang if using jpegs. There is another process windows does to convert the jpeg to a bitmap before setting it as wallpaper. If you can write that part of the code we can add it to the script so it will then accept jpegs. The same would need to happen for gif,png, etc but I do not kno whow to write an image conversion program using pure vbs.

maybe a way to script paint.exe into doing it for us behind the scenes and then setting the converted image as wallpaper?

Posted

lol just let me use VB6 and its done :P, how about a all to bmp application, then u can still use ur out dated batch and VBS scripts :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...