Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

InetGet Command.

$
0
0

Hello all,

 

 

I am trying to get a script together for downloading a file, installing it, then delete the file... So far I have been able to put peace by peace together and it is working. They only opportunity that I am running into is when a user puts in the wrong credentials to get to the setup the script will continue running down the script. I wanted to display a Message if the inetget command timesout or fails to just kill the script and display a message error or something..  FYI I am very new with Autoit. The Help File is great but there something that I am still learning. Any help will be greatly appreciated..

 

Here what I have so far

AutoIt         
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ProgressConstants.au3> #include <Constants.au3> #RequireAdmin _SelfDelete() While 1         $OPIDCHK = InputBox("Security Checkpoint", "Enter OPID:","", "")     If @error = "1" Then exit         If StringLen($OPIDCHK) <> 6 Then         MsgBox(48, "Error!", "OPID NOT VALID.")         Continueloop                 EndIf     ExitLoop     WEnd     While 2         $PASSCHK = InputBox("Security Checkpoint", "Enter PASSWORD:","", "*")     If @error = "1" Then exit         If StringLen($PASSCHK) < 7 Then          MsgBox (48, "Error!", "PASSWORD NOT VALID.")          ContinueLoop                    EndIf     ExitLoop       WEnd    Opt("TrayMenuMode", 1) $Form1              = GUICreate("Downloader", 400, 170, -1, -1) $pb_File            = GUICtrlCreateProgress(30, 30, 300, 20, $PBS_SMOOTH) $lbl_FilePercent    = GUICtrlCreateLabel("0 %", 335, 32, 35, 16, $SS_RIGHT) $but_Download       = GUICtrlCreateButton("Download", 160, 120, 80, 30) GUISetState(@SW_Show) While 1         $nMsg = GUIGetMsg()         If $nMsg = $GUI_EVENT_CLOSE Then EXIT             If $nMsg = $but_Download Then _Download()     WEnd Func _Download()         ; Disable the download button     GUICtrlSetState($but_Download, $GUI_DISABLE)         ; Reset total filesize to download     $TotalToDownload = 0         Dim $DownloadArray[8][3]         ; Setup the URL's to download     $DownloadArray[1][0] = "https://" & $OPIDCHK & ":" & $PASSCHK & "@websitegoeshere/setup64.exe"     $PATH = @TempDir & "\setup64.exe"         For $i = 1 To UBound($DownloadArray)-1                 ; Get the File size         $FileSize = INetGetSize($DownloadArray[$i][0])                 ; Current File Size         $DownloadArray[$i][1] = $FileSize                 ; Cumulative Total         $DownloadArray[$i][2] = $TotalToDownload                 ; Add the current file size to the total         $TotalToDownload += $FileSize     Next         ; Do the Downloads     For $i = 1 To UBound($DownloadArray)-1                 ; Dow the download in the background         $Download = INetGet($DownloadArray[$i][0],$PATH,1,1)                 ; Loop to update progress         Do             ; Get number of bytes read for current file             $BytesDownloaded    = INetGetInfo($Download, 0)                         ; Add this to the cumulative total             $DownloadedSoFar    = $DownloadArray[$i][2] + $BytesDownloaded                         ; Calculate the current file percentage             $FileProgress       = Floor(($BytesDownloaded / $DownloadArray[$i][1]) * 100)                         ; Calculate the overall percentage             $OverallProgress    = Floor(($DownloadedSoFar / $TotalToDownload) * 100)                         ; Update the Current FIle progress bar             GUICtrlSetData($pb_File, $FileProgress)                         ; Only update the current file percent label if it has changed to avoid flickering             If GUICtrlRead($lbl_FilePercent) <> $FileProgress & " %" Then GUICtrlSetData($lbl_FilePercent, $FileProgress & " %")                         ; Only update the title bar (overall) percent label if it has changed to avoid flickering             If WinGetTitle($Form1, "") <> $OverallProgress & " % - Downloader" Then WinSetTitle($Form1, "", $OverallProgress & " % - Downloader")                         ; Continue loop until download is complete             Until InetGetInfo($Download, 2)                                  ; Set current file progress bar to 100% when complete            GUICtrlSetData($pb_File, 100)                    ; Set current file percent label to 100% when complete            GUICtrlSetData($lbl_FilePercent, "100 %")                            Next          MsgBox (0, "Download", "Download completed. Click ok to continue installation")          RunWait($PATH)          FileDelete (@TempDir & "\setup64.exe")          Exit          EndFunc Func _SelfDelete($iDelay = 0)     Local $sCmdFile     FileDelete(@TempDir & "scratch.bat")     $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _              & ':loop' & @CRLF _              & 'del "' & @ScriptFullPath & '"' & @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

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>