Help - Search - Members - Calendar
Full Version: AutoIt script to change desktop
MSFN Forums > Customizing Windows and Graphics > Windows Desktops Screenshots

   
Google Internet Forums Unattended CD/DVD Guide
aboutblank
Hey guys. I LOVE THE FORUM!

I couldn't find anywhere else to put this, so I decided to post it here.

This AutoIt script will grab a random .bmp from a given directory and set it as the desktop. Change $favDir to your own directory from which to grab. Irfanview can be used to convert .jpgs to .bmps. Windows actually only can load .bmps to the desktop and usually does the conversion on-the-fly when you set a .jpg to the desktop. Hope it's appreciated smile.gif Personally, I have a startup item linking to the script so it changes when Windows starts.

PLEASE NOTE: I have used stolen code in this script. I don't know where it came from. Some of it is my work, some of it is not.

CODE
Dim $favDir = 'C:\Downloads\Wallpapers\favorites\'

Dim $cCounter = 0
Dim $FindFile = FileFindFirstFile($favDir & '*.bmp')
While 1
    FileFindNextFile($FindFile)
    If @error Then ExitLoop
    $cCounter = $cCounter + 1
WEnd
FileClose($FindFile)

$FindFile = FileFindFirstFile($favDir & '*.bmp')
Dim $RandomNum = Random(1, $cCounter, 1)

Dim $curFile
For $i = 1 To $RandomNum
    $curFile = FileFindNextFile($FindFile)
     If $RandomNum = $i Then
         ChangeDesktopWallpaper($favDir & $curFile)
         ExitLoop
     EndIf
Next

FileClose($FindFile)

Exit

Func ChangeDesktopWallpaper($bmp)
;===============================================================================
; Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp')
; Parameter(s): $bmp - Full Path to BitMap File (*.bmp)
; Requirement(s): None.
; Return Value(s): On Success - Returns 0
; On Failure - -1
;===============================================================================

If Not FileExists($bmp) Then Return -1
;The $SPI* values could be defined elsewhere via #include - if you conflict,
; remove these, or add if Not IsDeclared "SPI_SETDESKWALLPAPER" Logic
Local $SPI_SETDESKWALLPAPER = 20
Local $SPIF_UPDATEINIFILE = 1
Local $SPIF_SENDCHANGE = 2
Local $REG_DESKTOP= "HKEY_CURRENT_USER\Control Panel\Desktop"

;Don't tile -  just center
RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0)
RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0)
RegWrite($REG_DESKTOP, "Wallpaper", "REG_SZ", $bmp)

DllCall("user32.dll", "int", "SystemParametersInfo", _
"int", $SPI_SETDESKWALLPAPER, _
"int", 0, _
"str", $bmp, _
"int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE))

Return 0
EndFunc;==>_ChangeDestopWallpaper
SmOke_N
QUOTE (aboutblank @ Jun 17 2006, 01:13 PM) *
PLEASE NOTE: I have used stolen code in this script. I don't know where it came from. Some of it is my work, some of it is not.

cool.gif Maybe Here?
mfjkd
nice sharing
--=ddSHADOW=--
QUOTE (SmOke_N @ Jun 20 2006, 03:54 AM) *
QUOTE (aboutblank @ Jun 17 2006, 01:13 PM) *
PLEASE NOTE: I have used stolen code in this script. I don't know where it came from. Some of it is my work, some of it is not.

cool.gif Maybe Here?


man this is some nice program u got there EnCodeIt thumbup.gif
SmOke_N
QUOTE (--=ddSHADOW=-- @ Jun 24 2006, 03:55 PM) *
QUOTE (SmOke_N @ Jun 20 2006, 03:54 AM) *
QUOTE (aboutblank @ Jun 17 2006, 01:13 PM) *
PLEASE NOTE: I have used stolen code in this script. I don't know where it came from. Some of it is my work, some of it is not.

cool.gif Maybe Here?


man this is some nice program u got there EnCodeIt thumbup.gif

Thanks ;)
snow2000
Very Nice thx
Ryuho
Sorry to bring up such an old thread, but I need help getting this piece of code to work.

My OS is XP PS3 with the latest AutoIt compiler and SciTE

I run the code, and the wallpaper doesn't change, so I right click on my desktop and go to Properties. I noticed that the preview image on the properties window now has changed to one of the specified wallpaper, I click some other wallpaper and reselect the previously selected wallpaper (which is one of the wallaper that the autoit script selected) and I hit Ok, the wallpaper changed to one of the correct wallpaper.

So I think the wallpaper just needs to get refreshed.. but I don't know how I would do that.. Any Help? I just want a script/program/command to be able to select a random wallpaper from a directory and set it as the wallpaper when I want to.
MadBoy
QUOTE (Ryuho @ Sep 4 2008, 06:47 PM) *
Sorry to bring up such an old thread, but I need help getting this piece of code to work.

My OS is XP PS3 with the latest AutoIt compiler and SciTE

I run the code, and the wallpaper doesn't change, so I right click on my desktop and go to Properties. I noticed that the preview image on the properties window now has changed to one of the specified wallpaper, I click some other wallpaper and reselect the previously selected wallpaper (which is one of the wallaper that the autoit script selected) and I hit Ok, the wallpaper changed to one of the correct wallpaper.

So I think the wallpaper just needs to get refreshed.. but I don't know how I would do that.. Any Help? I just want a script/program/command to be able to select a random wallpaper from a directory and set it as the wallpaper when I want to.


Kill the explorer.exe, and rerun it. Maybe this will fix it?
Ryuho
It didn't work, and besides that would suck if I had to restart my shell and file browser each time I wanted to change my wallpaper...
jozuman
hey... this is freakin awesome. but how do you get it to be stretched, not centered. (i'm new here.)
Ryuho
I'm still having trouble using this peice of script.. does anyone have an alternative autoit script that I can try out?

Or can anyone tell me how to refresh the wallpaper without shutting down explorer?
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.