Sign in to follow this  
Followers 0
Chimaera

ShellExecute doesn't seem to trigger every time?

25 posts in this topic

#1 ·  Posted (edited)

Got an install script with a few tools tied to buttons

One of the buttons the tool tied to it which is NDoG's background changer and a bit of OS detection etc thrown in will not reliably trigger its button 5 in this snippet

Case $Button5
ShellExecuteWait(@ScriptDir & "Softwarebackgroundschanger.exe")
Case $Button6
ShellExecute(@ScriptDir & "Softwarecdgonecdgone.reg")

All the others work fine just this one, i tried run and run wait and shellexecute and shellexecutewait etc but some machines it triggers others it doesn't and i cant seem to work out why its odd?

If i run the exe on its own it works perfect everytime

Any thoughts

edit if it helps both exes have require admin and the machines are different OS's

Edited by Chimaera

Share this post


Link to post
Share on other sites



Chimaera,

You've probably done this already, but, put a consolewrite after the case stmt for the suspect buttons to make sure that they are not being actioned (as opposed to something else going wrong).

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yeah the button appears to be triggered properly.

The script it triggers isn't complex or massive it just checks the screen size and sets the appropriate company wallpaper for that size of screen and OS

The change part is this

Its weird how there is no fixed pattern ie it doesn't like XP etc

It definatly doesn't like just run or shellexecute, it doesn't even try with those it seems to need the wait part to enable the script.

I may have to add the scripts together in the end

Anyway ive made some changes again so ill keep testing

Edited by Chimaera

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ive changed it to this now

ShellExecute(@ScriptDir & "Softwarebackgroundschanger.exe", "", "", "open")
MsgBox(0, "Errorcode", @error & " / " & @extended)

Oddly even though it works on my machine it reports 0 as the error, when i assumed it should be 1

Success: Returns 1.

Failure: Returns 0 and sets @error to non-zero.

So maybe there is something wrong

ill report back when ive run it across a number of machines to get a bigger picture

Edited by Chimaera

Share this post


Link to post
Share on other sites

Ive changed it to this now

ShellExecute(@ScriptDir & "Softwarebackgroundschanger.exe", "", "", "open")
MsgBox(0, "Errorcode", @error & " / " & @extended)

Oddly even though it works on my machine it reports 0 as the error, when i assumed it should be 1

So maybe there is something wrong

ill report back when ive run it across a number of machines to get a bigger picture

That is correct.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

ShellExecute only tells you if it could run the program, it doesn't tell you if the program executed what it's supposed to do correctly. Unless the script has an exitcode that tells the calling program that there was an error, then even using ShellExecuteWait won't tell you anything.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Chimaera,

The result from shellexecute has nothing to do with whatever you are running. I believe that it just means that it was able to find the resource and launch it. In the following example the first line fails and returns the appropriate code, the second line runs and returns success. However, the script has no idea what the program executed in the second line is doing.

consolewrite('file does not exist ' & shellexecute(@scriptdir & 'file.that.does.not.exist') & @lf)
consolewrite('This does exist    ' & shellexecute('notepad.exe') & @lf)

I would look closely at whatever you are executing, especially at run time parms that might aid in debugging.

Good Luck,

kylomas

edit: Pretty much what BewmanNH said, more succinctly.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Why not use run instead?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Why not use run instead?

Because they all are twitchy Run/Runwait/ShellExecute/ShellExecuteWait

Ive made a test of each one now with error checking and ill run them till i can narrow it down

@JohnOne the target is one of my scripts as explained above

Share this post


Link to post
Share on other sites

Tested on my win 7 machine with no errors and works fine, took it to work with shellexecutewait in use and first win 7 machine it returned 0/0 but failed to change the background, the only difference i could see was it was doing updates and installing software at the same time.

Ill keep testing

Share this post


Link to post
Share on other sites

chimaera,

Have you looked at the Windows logs on the affected machine?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Failed again today on 2 machines (One fresh install the other one of our machines 8 months into an install)

I tried ShellExecute and ShellExecuteWait neither worked and both returned 0/0

ShellExecute(@ScriptDir & "\Toolz\chimaera\backgrounds\wallpaper_changer.exe", "", "", "open")
MsgBox(0, "Errorcode", @error & " / " & @extended)

I also made a version with the original code added into the main script and ran it like that and it failed as well ???

This is the code im using to change the desktop

_Desktop_Resolution()
#include <GDIPlus.au3>
Global $resolution, $OS, $dest_dir
Global $os_test = _OsDetect()
_Desktop_Resolution()
;===============================================================================
Func _Desktop_Resolution()
Switch $resolution = ""
;===============================================================================
Case @DesktopWidth = 1024 And @DesktopHeight = 600; 1024x600
FileCopy(@WorkingDir & "\TS_1024x600.jpg", $dest_dir & "\TS_1024x600.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1024x600.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1024 And @DesktopHeight = 768; 1024x768
FileCopy(@WorkingDir & "\TS_1024x768.jpg", $dest_dir & "\TS_1024x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1024x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1152 And @DesktopHeight = 864; 1152x864
FileCopy(@WorkingDir & "\TS_1152x864.jpg", $dest_dir & "\TS_1152x864.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1152x864.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 720; 1280x720
FileCopy(@WorkingDir & "\TS_1280x720.jpg", $dest_dir & "\TS_1280x720.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1280x720.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 768; 1280x768
FileCopy(@WorkingDir & "\TS_1280x768.jpg", $dest_dir & "\TS_1280x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1280x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 800; 1280x800
FileCopy(@WorkingDir & "\TS_1280x800.jpg", $dest_dir & "\TS_1280x800.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1280x800.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 960; 1280x960
FileCopy(@WorkingDir & "\TS_1280x960.jpg", $dest_dir & "\TS_1280x960.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1280x960.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 1024; 1280x1024
FileCopy(@WorkingDir & "\TS_1280x1024.jpg", $dest_dir & "\TS_1280x1024.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1280x1024.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1360 And @DesktopHeight = 768; 1360x768
FileCopy(@WorkingDir & "\TS_1360x768.jpg", $dest_dir & "\TS_1360x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1360x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1366 And @DesktopHeight = 768; 1366x768
FileCopy(@WorkingDir & "\TS_1366x768.jpg", $dest_dir & "\TS_1366x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1366x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1440 And @DesktopHeight = 900; 1440x900
FileCopy(@WorkingDir & "\TS_1440x900.jpg", $dest_dir & "\TS_1440x900.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1440x900.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1400 And @DesktopHeight = 1050; 1400x1050
FileCopy(@WorkingDir & "\TS_1400x1050.jpg", $dest_dir & "\TS_1400x1050.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1400x1050.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1600 And @DesktopHeight = 900; 1600x900
FileCopy(@WorkingDir & "\TS_1600x900.jpg", $dest_dir & "\TS_1600x900.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1600x900.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1600 And @DesktopHeight = 1200; 1600x1200
FileCopy(@WorkingDir & "\TS_1600x1200.jpg", $dest_dir & "\TS_1600x1200.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1600x1200.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1680 And @DesktopHeight = 1050; 1680x1050
FileCopy(@WorkingDir & "\TS_1680x1050.jpg", $dest_dir & "\TS_1680x1050.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1680x1050.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1920 And @DesktopHeight = 1080; 1920x1080
FileCopy(@WorkingDir & "\TS_1920x1080.jpg", $dest_dir & "\TS_1920x1080.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "\TS_1920x1080.jpg", 2)
;===============================================================================
Case Else
Exit
EndSwitch
EndFunc ;==>_Desktop_Resolution
;===============================================================================

Func _ChangeWallpaper($sFile, $iType)
Local $apos, $bpos, $sFileName, $hImage, $sCLSID
; Changes the wallpaper to $sFileName using $iType as:
; 1 Tiled
; 2 Centered
; 3 Stretched
; any other value (usually 0) unchanged
;
; Returns
; 0 if everything is allright.
; -1 if $sFile does not exist. @error is set to 1
; -2 if $sFile is not bmp or jpg file. @error is set to 2

If Not FileExists($sFile) Then
SetError(1)
Return -1
EndIf
$apos = StringInStr($sFile, "\", 0, -1)
$bpos = StringInStr($sFile, ".", 0, -1)

$sFileName = StringMid($sFile, $apos + 1, $bpos - $apos - 1)
;~ ConsoleWrite($sFileName & @CRLF)
If Not StringRight($sFile, 3) = "jpg" Or Not StringRight($sFile, 3) = "bmp" Then
SetError(2)
Return -2
EndIf
Select
Case $iType = 1
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '1')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 2
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 3
RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2')
Case Else
EndSelect
; Convert jpg to bmp
If StringRight($sFile, 3) = "jpg" Then
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFile)
$sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage, @TempDir & "\" & $sFileName & ".bmp", $sCLSID)
_GDIPlus_Shutdown()
$sFile = @TempDir & "\" & $sFileName & ".bmp"
EndIf
Sleep(500)
RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)
EndFunc ;==>_ChangeWallpaper

;===============================================================================

Func _OsDetect()
If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Then
$OS = "V-"
$dest_dir = "C:\Windows\Web\Wallpaper"
Else
$OS = "V+"
$dest_dir = "C:\Windows\Web\Wallpaper\Windows"
EndIf
;~ ConsoleWrite($OS & @CRLF)
Return $OS
EndFunc ;==>_OsDetect

And if i run it from the normal exe it works fine ..Gr$@##!!

The other code is just a button, nothing fancy

This is proper getting on my wick now

Share this post


Link to post
Share on other sites

If you remove the #RequireAdmin from the script, does it work? Because when you use RequireAdmin, it restarts the script using different credentials than the user, so it's probably changing the background for the Admin and not the user.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

No difference im afraid and most of the machines we do are admin single account.

I just made this up to double check and it doesn't even work on my machine anymore.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include 
#include 
#include 
; ------------------------------------------------------------------------------

Global $resolution, $OS, $dest_dir
Global $os_test = _OsDetect()


Global $button1, $button2
Local $GUI_Start = GUICreate(" Gui Test", 500, 500, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))

$button1 = GUICtrlCreateButton( " Test 1 ", 20, 50, 130, 35)
GUICtrlSetFont(-1, 11, 550, -1, "Tahoma")
$button2 = GUICtrlCreateButton( " Test 2 ", 20, 100, 130, 35)
GUICtrlSetFont(-1, 11, 550, -1, "Tahoma")
GUISetState()

Local $nMsg = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
ShellExecute(@ScriptDir & "Toolzchimaerabackgroundswallpaper_changer.exe", "", "", "open")
MsgBox(0, "Errorcode", @error & " / " & @extended)
Case $button2
_Desktop_Resolution()
EndSwitch
WEnd



;===============================================================================
Func _Desktop_Resolution()
Switch $resolution = ""
;===============================================================================
Case @DesktopWidth = 1024 And @DesktopHeight = 600; 1024x600
FileCopy(@WorkingDir & "TS_1024x600.jpg", $dest_dir & "TS_1024x600.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1024x600.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1024 And @DesktopHeight = 768; 1024x768
FileCopy(@WorkingDir & "TS_1024x768.jpg", $dest_dir & "TS_1024x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1024x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1152 And @DesktopHeight = 864; 1152x864
FileCopy(@WorkingDir & "TS_1152x864.jpg", $dest_dir & "TS_1152x864.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1152x864.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 720; 1280x720
FileCopy(@WorkingDir & "TS_1280x720.jpg", $dest_dir & "TS_1280x720.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1280x720.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 768; 1280x768
FileCopy(@WorkingDir & "TS_1280x768.jpg", $dest_dir & "TS_1280x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1280x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 800; 1280x800
FileCopy(@WorkingDir & "TS_1280x800.jpg", $dest_dir & "TS_1280x800.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1280x800.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 960; 1280x960
FileCopy(@WorkingDir & "TS_1280x960.jpg", $dest_dir & "TS_1280x960.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1280x960.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1280 And @DesktopHeight = 1024; 1280x1024
FileCopy(@WorkingDir & "TS_1280x1024.jpg", $dest_dir & "TS_1280x1024.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1280x1024.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1360 And @DesktopHeight = 768; 1360x768
FileCopy(@WorkingDir & "TS_1360x768.jpg", $dest_dir & "TS_1360x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1360x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1366 And @DesktopHeight = 768; 1366x768
FileCopy(@WorkingDir & "TS_1366x768.jpg", $dest_dir & "TS_1366x768.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1366x768.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1440 And @DesktopHeight = 900; 1440x900
FileCopy(@WorkingDir & "TS_1440x900.jpg", $dest_dir & "TS_1440x900.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1440x900.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1400 And @DesktopHeight = 1050; 1400x1050
FileCopy(@WorkingDir & "TS_1400x1050.jpg", $dest_dir & "TS_1400x1050.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1400x1050.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1600 And @DesktopHeight = 900; 1600x900
FileCopy(@WorkingDir & "TS_1600x900.jpg", $dest_dir & "TS_1600x900.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1600x900.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1600 And @DesktopHeight = 1200; 1600x1200
FileCopy(@WorkingDir & "TS_1600x1200.jpg", $dest_dir & "TS_1600x1200.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1600x1200.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1680 And @DesktopHeight = 1050; 1680x1050
FileCopy(@WorkingDir & "TS_1680x1050.jpg", $dest_dir & "TS_1680x1050.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1680x1050.jpg", 2)
;===============================================================================
Case @DesktopWidth = 1920 And @DesktopHeight = 1080; 1920x1080
FileCopy(@WorkingDir & "TS_1920x1080.jpg", $dest_dir & "TS_1920x1080.jpg", 9)
Sleep(1000)
_ChangeWallpaper($dest_dir & "TS_1920x1080.jpg", 2)
;===============================================================================
Case Else
Exit
EndSwitch
EndFunc ;==>_Desktop_Resolution
;===============================================================================

Func _ChangeWallpaper($sFile, $iType)
Local $apos, $bpos, $sFileName, $hImage, $sCLSID
; Changes the wallpaper to $sFileName using $iType as:
; 1 Tiled
; 2 Centered
; 3 Stretched
; any other value (usually 0) unchanged
;
; Returns
; 0 if everything is allright.
; -1 if $sFile does not exist. @error is set to 1
; -2 if $sFile is not bmp or jpg file. @error is set to 2

If Not FileExists($sFile) Then
SetError(1)
Return -1
EndIf
$apos = StringInStr($sFile, "", 0, -1)
$bpos = StringInStr($sFile, ".", 0, -1)

$sFileName = StringMid($sFile, $apos + 1, $bpos - $apos - 1)
;~ ConsoleWrite($sFileName & @CRLF)
If Not StringRight($sFile, 3) = "jpg" Or Not StringRight($sFile, 3) = "bmp" Then
SetError(2)
Return -2
EndIf
Select
Case $iType = 1
RegWrite('HKCUControl PanelDesktop', 'TileWallpaper', 'reg_sz', '1')
RegWrite('HKCUControl PanelDesktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 2
RegWrite('HKCUControl PanelDesktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCUControl PanelDesktop', 'WallpaperStyle', 'reg_sz', '0')
Case $iType = 3
RegWrite('HKCUControl PanelDesktop', 'TileWallpaper', 'reg_sz', '0')
RegWrite('HKCUControl PanelDesktop', 'WallpaperStyle', 'reg_sz', '2')
Case Else
EndSelect
; Convert jpg to bmp
If StringRight($sFile, 3) = "jpg" Then
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFile)
$sCLSID = _GDIPlus_EncodersGetCLSID("BMP")
_GDIPlus_ImageSaveToFileEx($hImage, @TempDir & "" & $sFileName & ".bmp", $sCLSID)
_GDIPlus_Shutdown()
$sFile = @TempDir & "" & $sFileName & ".bmp"
EndIf
Sleep(500)
RegWrite('HKCUControl PanelDesktop', 'Wallpaper', 'reg_sz', $sFile)
DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)
EndFunc ;==>_ChangeWallpaper

;===============================================================================

Func _OsDetect()
If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Then
$OS = "V-"
$dest_dir = "C:WindowsWebWallpaper"
Else
$OS = "V+"
$dest_dir = "C:WindowsWebWallpaperWindows"
EndIf
;~ ConsoleWrite($OS & @CRLF)
Return $OS
EndFunc ;==>_OsDetect

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0