Reputation: 37
I am trying to download a software from ftp location. When the download is completed, installation should start. May i know how to check whether the Download is completed or not using VBscript.
This is the current logic I am using But i get Object Required:" error
I am instantiating the vbscript from jar file
set shell = wscript.CreateObject("WScript.Shell")
shell.AppActivate ("Internet Explorer")
Dim objHTTP
Do
wscript.sleep 100
Loop While( objHTTP.readyState <> 4 ) And ( objHTTP.readyState <> "complete" )
msgbox ("download completed")
Upvotes: 1
Views: 557
Reputation: 1471
shell and objHTTP objects are not linked together and they can't be. You can't check download started from shell with objHTTP, you need to manage the entire download with objHTTP object.
Here's what you can do to manage your download :
Const BINARY = 1
Const CREATE = 2
' Download 7-ZIP 64bits.
myUrl = "http://www.7-zip.org/a/7z938-x64.msi"
' Save to disk in that file.
myFile = "c:\temp\7z938-x64.msi"
Set oHttp = WScript.CreateObject("WinHttp.WinHttpRequest.5.1")
oHttp.open "Get", myURL, False
oHttp.send
Set oStream = WScript.CreateObject("ADODB.Stream")
oStream.type = BINARY
oStream.open
oStream.write oHTTP.ResponseBody
oStream.SaveToFile myFile, CREATE
ostream.Close
Also, not the most clean answer, but if you know it, you can check when the downloaded file reaches its size in your loop.
Upvotes: 1