MSFN Forum: AutoIt script to change desktop - MSFN Forum

Jump to content


Warning!

This forum is likely to contain threads with large image files, and as such those threads could be slow for 56/128kbps users!
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

AutoIt script to change desktop Rate Topic: -----

#1 User is offline   aboutblank 

  • Group: Members
  • Posts: 1
  • Joined: 17-June 06

Posted 17 June 2006 - 12:13 PM

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 File(s)


This post has been edited by aboutblank: 17 June 2006 - 12:18 PM



#2 User is offline   SmOke_N 

  • Group: Members
  • Posts: 3
  • Joined: 19-June 06

Posted 19 June 2006 - 07:54 PM

View Postaboutblank, on Jun 17 2006, 01:13 PM, said:

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 User is offline   mfjkd 

  • Group: Members
  • Posts: 4
  • Joined: 19-June 06

Posted 23 June 2006 - 11:47 AM

nice sharing

#4 User is offline   --=ddSHADOW=-- 

  • --=ddSHADOW=--
  • PipPip
  • Group: Members
  • Posts: 209
  • Joined: 08-August 04

Posted 24 June 2006 - 02:55 PM

View PostSmOke_N, on Jun 20 2006, 03:54 AM, said:

View Postaboutblank, on Jun 17 2006, 01:13 PM, said:

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

#5 User is offline   SmOke_N 

  • Group: Members
  • Posts: 3
  • Joined: 19-June 06

Posted 17 July 2006 - 11:17 AM

View Post--=ddSHADOW=--, on Jun 24 2006, 03:55 PM, said:

View PostSmOke_N, on Jun 20 2006, 03:54 AM, said:

View Postaboutblank, on Jun 17 2006, 01:13 PM, said:

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 User is offline   snow2000 

  • Group: Members
  • Posts: 3
  • Joined: 19-March 06

Posted 27 October 2006 - 09:17 AM

Very Nice thx

#7 User is offline   Ryuho 

  • Group: Members
  • Posts: 3
  • Joined: 04-September 08

Posted 04 September 2008 - 10:47 AM

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 User is offline   MadBoy 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 467
  • Joined: 21-February 05
  • OS:none specified
  • Country: Country Flag

Posted 04 September 2008 - 11:44 AM

View PostRyuho, on Sep 4 2008, 06:47 PM, said:

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 User is offline   Ryuho 

  • Group: Members
  • Posts: 3
  • Joined: 04-September 08

Posted 04 September 2008 - 04:53 PM

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 User is offline   jozuman 

  • Group: Members
  • Posts: 1
  • Joined: 11-September 08

Posted 11 September 2008 - 07:44 PM

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

#11 User is offline   Ryuho 

  • Group: Members
  • Posts: 3
  • Joined: 04-September 08

Posted 19 September 2008 - 07:25 AM

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 User is offline   anandchakru2 

  • Group: Members
  • Posts: 1
  • Joined: 29-January 09

  Posted 29 January 2009 - 02:22 AM

View Postjozuman, on Sep 11 2008, 08:44 PM, said:

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)

This post has been edited by anandchakru2: 29 January 2009 - 02:22 AM


#13 User is offline   Geej 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 634
  • Joined: 01-January 08
  • OS:XP Pro x86
  • Country: Country Flag

Posted 29 January 2009 - 08:16 AM

There are 3rd party tools that can do the job, such as Automatic Wallpaper Changer

#14 User is offline   Geej 

  • Senior Member
  • PipPipPipPip
  • Group: Members
  • Posts: 634
  • Joined: 01-January 08
  • OS:XP Pro x86
  • Country: Country Flag

Posted 28 September 2009 - 10:23 PM

Attached File  ChangeDesktopWallpaper.au3 (3.16K)
Number of downloads: 59
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.76K)
Number of downloads: 38

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy