Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

AutoIt script to change desktop

- - - - -

  • Please log in to reply
13 replies to this topic

#1
aboutblank

aboutblank
  • Member
  • 1 posts
  • Joined 17-June 06
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 :) 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.

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

Attached Files


Edited by aboutblank, 17 June 2006 - 12:18 PM.



How to remove advertisement from MSFN

#2
SmOke_N

SmOke_N
  • Member
  • 3 posts
  • Joined 19-June 06

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.

B) Maybe Here?

#3
mfjkd

mfjkd
  • Member
  • 4 posts
  • Joined 19-June 06
nice sharing

#4
--=ddSHADOW=--

--=ddSHADOW=--

    --=ddSHADOW=--

  • Member
  • PipPip
  • 209 posts
  • Joined 08-August 04

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.

B) Maybe Here?


man this is some nice program u got there EnCodeIt :thumbup
Images in signatures shall NOT exceed a total of 300x100 and 80kb - N1K

#5
SmOke_N

SmOke_N
  • Member
  • 3 posts
  • Joined 19-June 06

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.

B) Maybe Here?


man this is some nice program u got there EnCodeIt :thumbup

Thanks ;)

#6
snow2000

snow2000
  • Member
  • 3 posts
  • Joined 19-March 06
Very Nice thx

#7
Ryuho

Ryuho
  • Member
  • 3 posts
  • Joined 04-September 08
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.

#8
MadBoy

MadBoy

    Advanced Member

  • Member
  • PipPipPip
  • 467 posts
  • Joined 21-February 05
  • OS:none specified
  • Country: Country Flag

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?

#9
Ryuho

Ryuho
  • Member
  • 3 posts
  • Joined 04-September 08
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...

#10
jozuman

jozuman
  • Member
  • 1 posts
  • Joined 11-September 08
hey... this is freakin awesome. but how do you get it to be stretched, not centered. (i'm new here.)

#11
Ryuho

Ryuho
  • Member
  • 3 posts
  • Joined 04-September 08
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?

#12
anandchakru2

anandchakru2
  • Member
  • 1 posts
  • Joined 29-January 09

hey... this is freakin awesome. but how do you get it to be stretched, not centered. (i'm new here.)



Change

RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0)

to

RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 2)

Edited by anandchakru2, 29 January 2009 - 02:22 AM.


#13
Geej

Geej

    Senior Member

  • Member
  • PipPipPipPip
  • 635 posts
  • Joined 01-January 08
  • OS:XP Pro x86
  • Country: Country Flag
There are 3rd party tools that can do the job, such as Automatic Wallpaper Changer

#14
Geej

Geej

    Senior Member

  • Member
  • PipPipPipPip
  • 635 posts
  • Joined 01-January 08
  • OS:XP Pro x86
  • Country: Country Flag
Attached File  ChangeDesktopWallpaper.au3   3.16KB   69 downloads
I have attempt to modify the script to make it work with all images type (.png, .bmp, jpg etc). Since it need to be converted to bmp, I use IrfanView main executable to do this task. Hence for the script to work, it requires you to put i_view32.exe in either the same folder as the script or C:\Windows. (I prefer C:\Windows)
Image location is C:\WINDOWS\Web\Wallpaper
I have included the modified script (as in the above) for you to edit as well as the compiled script (as in below) so that non-autoit user can also use it.
Tested in XP only. Enjoy :)

Attached File  ChangeDesktopWallpaper.exe   285.76KB   54 downloads




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users



How to remove advertisement from MSFN