hogfan Posted October 14, 2011 Share Posted October 14, 2011 I have a separate script that is compiled to an executable that my AutoIT application calls via a ShellExecute command when the application is started. The called script is an update script that checks for a new version of the application on a network share. The script has been working well until recently. The update script keeps going into a paused state on some users machines and I am trying to figure out why. Here is the code for my script that checks for updates to my main application: expandcollapse popup#Include <Misc.au3> ;Check if the network share is available ;Get the UpdatePath from the settings.ini file on users machine $updatePath = IniRead(@ScriptDir & "\settings.ini", "UPDATE PATH", "Path", "default") ;Set UpdateDirectory equal to $UpdatePath $updateDirectory = $UpdatePath If FileExists("\\UpdateServer\updater\current_version\MyApp.exe") Then ;get file versions $sVersion1 = $UpdatePath & "\MyApp.exe" $sVersion2 = @ScriptDir & "/MyApp.exe" ;compare versions $result = _VersionCompare(FileGetVersion($sVersion1), FileGetVersion($sVersion2)) ;Msgbox(0,"", "Remote file is version: " & FileGetVersion($sVersion1) & " Local file is version: " & FileGetVersion($sVersion2)) ;if local version is older than remote version If $result = 1 Then Msgbox(64,"Update Available!", "A new version of MyApp is available! It will be downloaded and installed now!") ;Kill MyApp process ProcessClose("MyApp.exe") ;make sure update status is 0 by default $updateStatus = 0 ;Update MyApp Files While Not $updateStatus = 1 $updateStatus = DirCopy($updateDirectory, @ScriptDir, 1) WEnd Msgbox(64, "Update Complete!", "MyApp has been successfully updated!") ;relaunch MyApp ShellExecute(@ScriptDir & "/MyApp.exe") ;Display the changelog ShellExecute(@ScriptDir & "/changelog.txt") Exit EndIf Else Exit Endif I think this area of the code may be causing the script to pause, but it is not happening on all machines, only some. ;Update MyApp Files While Not $updateStatus = 1 $updateStatus = DirCopy($updateDirectory, @ScriptDir, 1) WEnd Also, all users have access to the network share. Any suggestions on ironing out this issue are much appreciated. Initially, I didn't have the while loop in there for the DirCopy, but before I added that some users were getting and infinite loop of the application saying there was a new version available.........like it was checking for a new version again before the DirCopy process had completed. Adding the while statement to the DirCopy bit of code eliminated that issue, but now this other issue with the script pausing has been introduced just in the last week. Link to comment Share on other sites More sharing options...
Spiff59 Posted October 14, 2011 Share Posted October 14, 2011 (edited) I think you need some more consistency on the forward slash and back slash. Edit: Wow, that's crazy. So much for (apparently former) rules. Run() and ShellExecute() don't care if it's forward or back. I've never used anything but a backslash for a filepath, and forward slash for a web address... Edited October 14, 2011 by Spiff59 Link to comment Share on other sites More sharing options...
hogfan Posted October 14, 2011 Author Share Posted October 14, 2011 I think you need some more consistency on the forward slash and back slash. Edit: Wow, that's crazy. So much for (apparently former) rules. Run() and ShellExecute() don't care if it's forward or back. I've never used anything but a backslash for a filepath, and forward slash for a web address... Good catch. I'll definitely fix that. That is what happens when you work with multiple Operating systems. / is always used on Mac OS and Linux and \ in Windows. I'll fix that but that doesn't appear to be the issue causing the script to pause. Link to comment Share on other sites More sharing options...
Spiff59 Posted October 14, 2011 Share Posted October 14, 2011 (edited) ProcessWaitClose() might be a good addition to what you have. And limiting the number of attempts for a DirCopy() with a delay built-in might be better: expandcollapse popup#Include <Misc.au3> $MyApp = "MyApp.exe" ;Get the UpdatePath from the settings.ini file on users machine $updatePath = IniRead(@ScriptDir & "\settings.ini", "UPDATE PATH", "Path", "default") $sPath1 = $UpdatePath & "\" & $MyApp $sPath2 = @ScriptDir & "\" & $MyApp ;Check if the network share is available If Not FileExists($sPath1) Then MsgBox(17, "Error", "MyApp not found at:" & @CRLF & $sPath1) Exit EndIf ;compare versions $sVersion1 = FileGetVersion($sPath1) $sVersion2 = FileGetVersion($sPath2) $result = _VersionCompare($sVersion2, $sVersion1) Msgbox(0,"", "Remote file is version: " & $sVersion1 & @CRLF & "Local file is version : " & $sVersion2) ;if local version is older than remote version If $result = 1 Then Msgbox(64,"Update Available!", "A new version of MyApp is available! It will be downloaded and installed now!") ;Kill local process ProcessClose($MyApp) If Not ProcessWaitClose($MyApp, 3) Then Msgbox(17, "Update Failed!", "Unable to close local process") Exit EndIf For $x = 1 to 3 If DirCopy($UpdatePath, @ScriptDir, 1) Then ExitLoop Sleep(1000) Next If $x > 3 Then Msgbox(17, "Update Failed!", "Unable to copy files") Else Msgbox(64, "Update Complete!", "MyApp has been successfully updated!") ;relaunch MyApp ShellExecute(@ScriptDir & "\" & $MyApp) ;Display the changelog ShellExecute(@ScriptDir & "\changelog.txt") Endif EndIf Edit: Added a timeout loop and error message to the process kill step Edited October 14, 2011 by Spiff59 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now