UrlDownloadToFile

Get help with using AutoHotkey and its commands and hotkeys
bona
Posts: 2
Joined: 06 Feb 2018, 14:31

UrlDownloadToFile

06 Feb 2018, 14:36

I am trying to use UrlDownloadToFile but nothing is happening. No errors popup neither the file is downloaded.

I'm basically using the same command from the documentation:

UrlDownloadToFile, https://autohotkey.com/download/1.1/version.txt, C:\temp\AutoHotkey Latest Version.txt

Do I need to do something before this? Open IE?
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: UrlDownloadToFile

06 Feb 2018, 14:57

Maybe the directory does not exist ?

Try in your script directory:

Code: Select all

UrlDownloadToFile, https://autohotkey.com/download/1.1/version.txt, %A_ScriptDir%\AutoHotkey Latest Version.txt
if errorlevel
msgbox error %errorlevel%
soundcloud.com/user-32706894
bona
Posts: 2
Joined: 06 Feb 2018, 14:31

Re: UrlDownloadToFile

06 Feb 2018, 15:13

noname wrote:Maybe the directory does not exist ?

Try in your script directory:

Code: Select all

UrlDownloadToFile, https://autohotkey.com/download/1.1/version.txt, %A_ScriptDir%\AutoHotkey Latest Version.txt
if errorlevel
msgbox error %errorlevel%
It does exist, however I still tried your way.

Got the message: "error 1"

And the file wasn't downloaded
garry
Posts: 2207
Joined: 22 Dec 2013, 12:50

Re: UrlDownloadToFile

06 Feb 2018, 15:43

I had no succes , also not with last version wget ( with XP )
this works ( UrlDownloadToFile )

Code: Select all

setworkingdir,%a_scriptdir%
A =%A_AHKVERSION%

f1:="https://autohotkey.com/download/1.1/version.txt"
SplitPath,f1, name, dir, ext, name_no_ext, drive
fd:=a_desktop                                         ;- save here

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.SetTimeouts(3000,3000,3000,3000)
global whr,fd

url:=WinHttp_UrlDownloadToFile(F1)
xxc=%fd%\%name%

fileread,B,%xxc%
   if (A<>B)
     {
     msgbox, 262436,AHK-Version ,(Changed)`nYour existing version is=%A%`n          Actual version is=%B%`n64-bit=%a_is64bitos%`nUnicode=%a_isunicode%`nOS=%a_osversion%`nWant you open Autohotkey downloads page ?
     IfMsgBox,No
       return
     Else
       {
       run,https://autohotkey.com/download/
       ;run,https://autohotkey.com/download/ahk-install.exe
       return
       }
     }
   else
     {
     msgbox, 262436,AHK-Version ,(Equal)`nYour existing version is=%A%`n           Actual version is=%B%`n64-bit=%a_is64bitos%`nUnicode=%a_isunicode%`nOS=%a_osversion%`nWant you open Autohotkey downloads page ?
     IfMsgBox,No
       return
     Else
       run,https://autohotkey.com/download/
    return
    }
return

;------------ urldownloadtofile user tmplinshi --------------------------------
WinHttp_UrlDownloadToFile(URL, Filename := "") {
	;WHR := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WHR.Open("GET", url, true)
	WHR.Send()
	WHR.WaitForResponse()

	if (Filename ~= "^\s*$") {
		try {
			RegExMatch( WHR.GetResponseHeader("Content-Disposition"), "filename=\K.+", Filename )
		} catch {
			RegExMatch( WHR.Option(1), "[^/]+$", Filename )    ;- 1 = WinHttpRequestOption_URL
		}
	}
	ADO := ComObjCreate("ADODB.Stream")
	ADO.Type := 1 ; adTypeBinary
	ADO.Open()
	ADO.Write(WHR.ResponseBody)
	ADO.SaveToFile(fd . "\" . FileName, 2)
	ADO.Close()
}
;========================================================================
EDIT : and this also ( urldownloadtovar )

Code: Select all

;- urldownloadtovar --------------------------------
#warn
setworkingdir,%a_scriptdir%
url:="https://autohotkey.com/download/1.1/version.txt"

a:= A_AHKVERSION
b:= URLDownloadToVar(url)

   if (A<>B)
     {
     msgbox, 262436,AHK-Version ,(Changed)`nYour existing version is=%A%`n          Actual version is=%B%`n64-bit=%a_is64bitos%`nUnicode=%a_isunicode%`nOS=%a_osversion%`nWant you open Autohotkey downloads page ?
     IfMsgBox,No
       return
     Else
       {
       run,https://autohotkey.com/download/
       ;run,https://autohotkey.com/download/ahk-install.exe
       return
       }
     }
   else
     {
     msgbox, 262436,AHK-Version ,(Equal)`nYour existing version is=%A%`n           Actual version is=%B%`n64-bit=%a_is64bitos%`nUnicode=%a_isunicode%`nOS=%a_osversion%`nWant you open Autohotkey downloads page ?
     IfMsgBox,No
       return
     Else
       run,https://autohotkey.com/download/
    return
    }
return

URLDownloadToVar(url){
    hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
    hObject.Open("GET",url)
    hObject.Send()
    return hObject.ResponseText
}
;==========================================================
User avatar
boiler
Posts: 4614
Joined: 21 Dec 2014, 02:44

Re: UrlDownloadToFile

06 Feb 2018, 17:24

You might want to check your security settings in IE. If they're set to be really strict, it may be preventing it from downloading the file. A good test is to paste that same URL into IE and see if it downloads it without giving you some message.

Return to “Ask For Help”

Who is online

Users browsing this forum: Conrad_Smuts, Eureka, HiSoKa, JawGBoi, just me and 235 guests