monte Posted November 1, 2007 Share Posted November 1, 2007 hello, in the beginning of my code I look for a newer version (on a network share) and if found copy it to my program's location (c:\program files\). Only it's not copying, is this because it can't over write a running executable? If anyone knows how to replace the current running version of a program with a newer one, please let me know. Thank you. ;make sure there are no updates if FileGetTime("\\network_file_share\myProgram directory\myProgram.exe", 0, 1) > FileGetTime(@ProgramFilesDir & "\myProgram directory\myProgram.exe", 0, 1) then filecopy("\\network_file_share\myProgram directory\myProgram.exe", @ProgramFilesDir & "\myProgram directory\myProgram.exe", 9) msgbox(0,"Program", "Newer version found, rerun the program after this window closes.") exit endif Link to comment Share on other sites More sharing options...
Blue_Drache Posted November 1, 2007 Share Posted November 1, 2007 Easy peasy. expandcollapse popupIf @Compiled Then _AutoUpdate($CmdLine, "C:\oldfile.exe", "C:\newfile.exe") #region Function: _AutoUpdate Func _AutoUpdate($sz_CommandParam, $sz_fileSelf, $sz_fileRemote) ;~ If @Compiled Then _AutoUpdate($CmdLine, "local", "remote") If WinExists("AutoUpdate") Then If Not WinWaitClose("AutoUpdate", "", 30) Then MsgBox(0, "AutoUpdate", "Error#:311" & @LF & "Error updating. Contact developer.") SetError(4) Return -1 EndIf EndIf Local $sz_dateSelf = "", $sz_dateRemote = "" Local $funcTemp = "", $t = "", $sz_WinTitleOld = AutoItWinGetTitle() Local $i_min = -3600, $i_max = 3600 AutoItWinSetTitle("AutoUpdate") If Not FileExists($sz_fileRemote) Then MsgBox(0, "AutoUpdate", "Error#:187" & @LF & "Update file not found. Program will continue normally") SetError(0) SetExtended(1) AutoItWinSetTitle($sz_WinTitleOld) Return 0 EndIf ; check here for command line parameters If $sz_CommandParam[0] > 0 Then ; commandline passed! If $sz_CommandParam[1] = "-update" Then ; 5a) If -update has been called, this is the temp file running. ; Copy the remote to the user's normal local folder, run the updated local, self-delete and exit. FileCopy($sz_fileRemote, $sz_fileSelf, 1) For $funcTemp = 0 To 2 FileSetTime($sz_fileSelf, FileGetTime($sz_fileRemote, $funcTemp, 1), $funcTemp) Sleep(10) Next MsgBox(0, $version, "Update to version " & FileGetVersion($sz_fileRemote) & " complete.") Run($sz_fileSelf) _SelfDelete() Exit Else ; 5b) If any other command line parameter has been called. Die. Horribly. [optional] ; MsgBox(0, "AutoUpdate", "Error#: 911" & @LF & "Bad Command Line Parameter(s)" & @LF & "I only accept -update at this time.") ; Exit EndIf Else ; no command line passed ; 1) Get file date on self. $t = FileGetTime($sz_fileSelf, 1) If Not @error Then $sz_dateSelf = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5] Else AutoItWinSetTitle($sz_WinTitleOld) SetError(1) Return -1 EndIf ; 2) Get file date on file in remote location $t = FileGetTime($sz_fileRemote, 1) If Not @error Then $sz_dateRemote = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5] Else AutoItWinSetTitle($sz_WinTitleOld) SetError(2) Return -1 EndIf ; 3) Determine if remote is newer $t = _DateDiff('s', $sz_dateSelf, $sz_dateRemote) If @error Then AutoItWinSetTitle($sz_WinTitleOld) SetError(3) Return -1 EndIf Switch $t Case $i_min To $i_max ; 4a) If the remote is an hour or less different, don't bother. AutoItWinSetTitle($sz_WinTitleOld) Return $t Case Else ; 4b) Otherwise, copy remote into temp folder with random name. ; Execute the temp with command line parameter and terminate. MsgBox(0, "AutoUpdate", "Starting Update Procedure", 10) $funcTemp = Random(1001, 9999, 1) FileCopy($sz_fileRemote, @TempDir & "\AUD-" & $funcTemp & ".exe") Run(@ComSpec & " /c " & @TempDir & '"\AUD-' & $funcTemp & '.exe" -update', "", @SW_HIDE) Exit EndSwitch EndIf EndFunc ;==>_AutoUpdate #endregion #region Function: _SelfDelete Func _SelfDelete($iDelay = 3) ; This is from the help file. Local $sCmdFile FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndFunc ;==>_SelfDelete #endregion Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache 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