Sign in to follow this  
Followers 0
derpitis

Autoit executing an exe too early.

4 posts in this topic

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)

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
Share on other sites

Before shellexecute check if the file exist in a loop and if not - wait.

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