I have modified the script to accept arguments from the command line. These are 2 in number and they are obligatory. 1. The url of the file you want to download 2. The folder you want to download it to.
To use the script from batch files do this
1. Save it somewhere on your hard drive. Give it a suitable name. I will use the name Downloader.vbs here.
2. run it with cscript if you want it to behave as a command line program, like this:
cscript //nologo c:\scripts\downloader.vbs "
http://www.robgendlerastropics.com/primer.html" "C:\downloads"
I don't know about exporting to Excel, sorry
myURL = wscript.arguments(0)
myPath = wscript.arguments(1)
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
If objFSO.FolderExists( myPath ) Then
strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
strFile = myPath
Else
WScript.Echo "ERROR: Target folder not found."
wscript.Quit
End If
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
'following line is optional
wscript.echo "Downloading " & myURL
objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )
'following line is optional
wscript.echo "Download complete"