Skip to content

Instantly share code, notes, and snippets.

@macostag
Created June 3, 2018 02:35
Show Gist options
  • Select an option

  • Save macostag/9325b166120256844fb7341f778b90c7 to your computer and use it in GitHub Desktop.

Select an option

Save macostag/9325b166120256844fb7341f778b90c7 to your computer and use it in GitHub Desktop.
Download files using VBscript
strUrl = WScript.Arguments.Item(0)
StrFile = Wscript.Arguments.Item(1)
Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const HTTPREQUEST_PROXYSETTING_PROXY = 2
Dim http,varByteArray,strData,strBuffer,lngCounter,fs,ts
Err.Clear
Set http = Nothing
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
If http Is Nothing Then Set http = CreateObject("WinHttp.WinHttpRequest")
If http Is Nothing Then Set http = CreateObject("MSXML2.ServerXMLHTTP")
If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
http.Open "GET",strUrl,False
http.Send
varByteArray = http.ResponseBody
set http = Nothing
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.CreateTextFile(StrFile,True)
strData = ""
strBuffer = ""
For lngCounter = 0 to UBound(varByteArray)
ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1,1)))
Next
ts.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment