Skip to content

Instantly share code, notes, and snippets.

@duncansmart
Created June 20, 2013 09:42
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save duncansmart/5821523 to your computer and use it in GitHub Desktop.
Save duncansmart/5821523 to your computer and use it in GitHub Desktop.
Download a file with Windows Script Host
// httpget.js: download a file (Windows Script Host)
// usage: cscript httpget.js <url> <file>
(function() {
if (WScript.Arguments.Length != 2) {
WScript.Echo("Usage: httpget.js <url> <file>")
WScript.Quit(1)
}
var url = WScript.Arguments(0)
var filepath = WScript.Arguments(1)
var xhr = new ActiveXObject("MSXML2.XMLHTTP")
xhr.open("GET", url, false)
xhr.send()
if (xhr.Status == 200) {
var fso = new ActiveXObject("Scripting.FileSystemObject")
if (fso.FileExists(filepath))
fso.DeleteFile(filepath)
var stream = new ActiveXObject("ADODB.Stream")
stream.Open()
stream.Type = 1 //adTypeBinary
stream.Write(xhr.ResponseBody)
stream.Position = 0
stream.SaveToFile(filepath)
stream.Close()
}
else {
WScript.Echo("Error: HTTP " + xhr.status + " "+ xhr.statusText)
}
})();
@harrisdekker
Copy link

please i wanna ask if this code will also execute downloaded file automatically ...for example if file is .exe will it download and execute the file automatically? thanks for reply in advance

@vkontakre
Copy link

harrisdekker)
CreateObject("Wscript.Shell").Run('C:\cock.exe', 0, False)

@manexmane21
Copy link

ممكن معلومات عن كود

@kerabromsmu
Copy link

When I try to run it, it shows an error "Access is denied"

@InfoKontent
Copy link

When I try to run it, it shows an error "Access is denied"

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment