Skip to content

Instantly share code, notes, and snippets.

@grey-code
Last active December 25, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save grey-code/7042282 to your computer and use it in GitHub Desktop.
Save grey-code/7042282 to your computer and use it in GitHub Desktop.
AutoHotkey: Download()
/*
Derived from Wicked - can't locate his thread but found this in the ff thread:
http://www.autohotkey.com/board/topic/97642-urldownloadtofile/#entry614852
*/
Download(url, dest) {
static r
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
if (!r || whr.Option(1) != url)
whr.Open("GET", url)
whr.Send()
if (whr.ResponseText = "failed" || whr.Status != 200 || ComObjType(whr.ResponseStream) != 0xd)
return false
p := ComObjQuery(whr.ResponseStream, "{0000000c-0000-0000-C000-000000000046}")
file := FileOpen(dest, "w")
Loop {
VarSetCapacity(bin, 8192)
r := DllCall(NumGet(NumGet(p+0)+3*A_PtrSize), "Ptr", p, "Ptr", &bin, "UInt", 8192, "Ptr*", c)
file.RawWrite(&bin, c)
} until (c == 0)
ObjRelease(p)
file.Close()
return whr.ResponseText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment