derpitis Posted March 21, 2016 Share Posted March 21, 2016 So I'm trying to have autoit download a patch, then wait till its downloaded and execute it but it's trying to instantly launch it saying obviously the file isnt found as it hasnt started the download yet. here's the code, any idea why this is happening? If ($patch1 > "0") Then InetGet($url, "patch.exe", 1, 1) $filesize = InetGetSize($url) While @InetGetActive TrayTip("Downloading patches", "Bytes = " & @InetGetBytesRead, 5, 16) GUICtrlSetData($progress, (@InetGetBytesRead / $filesize) * 100) Sleep(550) WEnd TrayTip("Updating Files", "Please Wait...", 5, 16) ShellExecute("patch.exe") Sleep(300) Link to comment Share on other sites More sharing options...
derpitis Posted March 21, 2016 Author Share Posted March 21, 2016 Oh nice to note that the file downloads still even after windows says "hey this file doesn't exist" so its just not properly waiting till its downloaded to execute it. Link to comment Share on other sites More sharing options...
InunoTaishou Posted March 22, 2016 Share Posted March 22, 2016 I haven't used @InetGetActive so I'm not sure if that's what's causing it. I don't even see that macro in the help file. Here's an example of downloading a large(ish) file and executing it when the file is complete using InetGetInfo #include <InetConstants.au3> Global Const $sDownloadUrl = "https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe" Global Const $sSaveAs = @ScriptDir & "\AutoIt V3 Setup.exe" Global $iStartTimer = 0 Global $hDownload = 0 Global $iDownloadSize = 0 Global $iDownloadSpeed = 0 Global $iBytesRead = 0 ProgressOn("Downloading", "Downloading AutoIt V3 Setup", "", -1, -1, 16) $iDownloadSize = InetGetSize($sDownloadUrl) $hDownload = InetGet($sDownloadUrl, $sSaveAs, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) $iStartTimer = TimerInit() While (Not InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)) Local $iPercent = ((InetGetInfo($hDownload, $INET_DOWNLOADREAD) * 100) / $iDownloadSize) $iBytesRead = InetGetInfo($hDownload, $INET_DOWNLOADREAD) ProgressSet($iPercent, Round($iPercent, 0) & "%" & @CRLF & "Downloaded " & Round(InetGetInfo($hDownload, $INET_DOWNLOADREAD) / 1048576, 2) & " of " & Round($iDownloadSize / 1048576, 2) & " MB (" & $iDownloadSpeed & "MB/s)") Sleep(200) $iDownloadSpeed = Round(((InetGetInfo($hDownload, $INET_DOWNLOADREAD) - $iBytesRead) / 1048576) * 5, 2) WEnd InetClose($hDownload) ShellExecute($sSaveAs) Link to comment Share on other sites More sharing options...
Juvigy Posted March 22, 2016 Share Posted March 22, 2016 Before shellexecute check if the file exist in a loop and if not - wait. 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