StuckUser Posted August 19, 2019 Posted August 19, 2019 (edited) So I am using code with some modifications I found from another member to make sure my program is always up to date. I had to modify his code because he was using a web server with InetGet. I am using FileInstall instead. I am having a very strange issue. It appears that the code partially runs and installs the update file. However, FileMove and Delete don't seem to execute. Even weirder still, the update file that is added is 1 version behind the file I am trying to pull from. Basically it seems to be re-updating with itself. I can't paste the true path for FileInstall to pull from because it contains company info, but I denoted it as "parentPath". Addtionally I have both the AutoItWrapper file version and #pragma file version but only the pragma seems to work. I could care less about this unless it somehow had an impact on my issue (doesn't appear to far as I can tell). expandcollapse popup#include <Array.au3> #include <Excel.au3> #include <EditConstants.au3> #include <MsgBoxConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <AutoItConstants.au3> #include <Date.au3> #include <INet.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <String.au3> #include <InetConstants.au3> #include <Inet.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <GuiEdit.au3> #Region #AutoIt3Wrapper_Icon=RedFlag.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Fileversion=5.0.0.0 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Run_Obfuscator=y #pragma compile(FileVersion, 8.0.0.0) #EndRegion Global $UpdatePathIs = @ScriptDir & "\update.exe"; This is the local path where you want your update to be downloaded into. Global $serverUpdateExe = "parentpath.exe"; This is the path to the update.exe file on your server. Global $ToBeReplacedPathIs = @ScriptDir & "\FieldOpsHelperWebpageBeta.exe"; This is the path to your original program that you want to update. Global $doDownload Global $updateFailed Global $retryornot ; ---- These are the two main functions to run GetCurrentSoftwareVersion() doVersionCheck() ;---- Func GetCurrentSoftwareVersion() ; Retrieve the file version of the target/original executable. | Retrieve the version number contained in your version.txt file. Global $localEXEversion = FileGetVersion(@ScriptDir & "\FieldOpsHelperWebpageBeta.exe") Global $remoteEXEversion = FileGetVersion("parentpath.exe") EndFunc ;==>GetCurrentSoftwareVersion Func doVersionCheck() ;check if local version is lower than server version - if server version higher than local version then push update If $localEXEversion < $remoteEXEversion Then MsgBox(0,"","server version higher - lets update it") FileInstall("parentpath.exe", @ScriptDir & "\update.exe") DownloadDeleteRename() Else MsgBox(0,"","server version lower than current local verison - no action needed"); we do "lower" so that when you are working on updates locally and testing, your script doesn't force you to update. EndIf EndFunc;doVersionCheck Func DownloadDeleteRename() FileDelete(@ScriptDir & "\FieldOpsHelperWebpageBeta.exe"); this will delete the original exe file FileMove(@ScriptDir & "\update.exe",@ScriptDir & "\FieldOpsHelperWebpageBeta.exe"); this will rename your update.exe to whatver your original exe file name was so that you have replaced the original exe with the updated exe ; lets check to make sure our update was successful - We do this by checking the local and remote file versions again... If the update was successful, then the local exe file and the remote version.txt file will be the same number. GetCurrentSoftwareVersion() MsgBox(0,"",$localEXEversion & $remoteEXEversion) If $localEXEversion = $remoteEXEversion Then ;all is good - the update was successful Global $updateFailed = false; this means the update did not fail ConsoleWrite($updateFailed) Else $retryornot = MsgBox(16 + 5,"Update error detected","Likely cause: Firewall/Antivirus prevented the download.") ;this tells us what button the user clicked on msgbox... cancel = 2, and retry = 4 Global $updateFailed = true; this means the update failed ConsoleWrite($updateFailed) EndIf ; with the if statement below we are telling the software to simply close if the user rejected our update instead of retrying. If $retryornot = 4 Then GetCurrentSoftwareVersion() doVersionCheck() Else ;close application ;Exit (remove this text and uncomment 'exit' to make the program actually close) EndIf EndFunc;DownloadDeleteRename I did not post the full program code as it should be irrelevant and I am unsure why half the code is in red when pasting it. Edited August 19, 2019 by StuckUser
StuckUser Posted August 24, 2019 Author Posted August 24, 2019 Anyone able to give me some help or suggestions on this one? Thanks.
brutal Posted August 27, 2019 Posted August 27, 2019 Just a guess on part of the issue you are running into... You said:: FileMove and Delete don't seem to execute. If the file is 'in use' then neither of those would work, both would fail... So, use a kill task to make that file accessible to the commands you are trying to run.
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