UrlDownloadToFile requirements

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Coderooney
Posts: 46
Joined: 23 Mar 2017, 22:41

UrlDownloadToFile requirements

20 Apr 2017, 19:50

I am losing my mind here. Here is the entirety of a script I'm trying to run:

Code: Select all

UrlDownloadToFile, http://autohotkey.com/download/1.1/version.txt, AutoHotkey.txt
As basic as it gets, right? Nothing happens though! UrlDownloadToFile is working just fine in more complex scripts, but for some reason it doesn't work in simple ones like this.

Is there some other bit of code that a script needs to be able to use UrlDownloadToFile?
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: UrlDownloadToFile requirements

20 Apr 2017, 20:04

I made a script with only that one line, and it works as expected. Meaning a file called AutoHotkey.txt appears in the same directory of the script, and contains the text 1.1.25.01.

I know this doesn't help solve your problem, but at least you know its not the code that is wrong. That's good right?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: UrlDownloadToFile requirements

20 Apr 2017, 20:14

CodeRooney wrote:Nothing happens
Like NightWolf85 said the script works as expected.

The file is supposed to appear in %A_WorkingDir% (the script own directory by default) if an absolute path isn't specified like in your case.
Also make sure you don't run the script from a directory like "Program Files" directory (this will avoid issues related to write privileges).

With the code above a txt file should appear in your destkop:

Code: Select all

UrlDownloadToFile, http://autohotkey.com/download/1.1/version.txt, %A_Desktop%/AutoHotkey.txt
Hope this helps.
my scripts
User avatar
Coderooney
Posts: 46
Joined: 23 Mar 2017, 22:41

Re: UrlDownloadToFile requirements

21 Apr 2017, 01:12

Nightwolf, that is definitely good! It means there is some firewall/DNS issue going on. What is strange is that it works in my other scripts, which are much more complex than a single basic line and even use expressions within the UrlDownloadToFile line.

AhkUser, yeah nothing appears in the default working directory and just in case, I searched the whole computer. No results. Will have to delve into the network side of things rather than the code itself.

Thank you both for you confirmation at least— that lets me know where to look for the problem.
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: UrlDownloadToFile requirements

21 Apr 2017, 15:25

here 3 examples

Code: Select all

;- 3 examples
;- if no succes with urldownloadtofile

setworkingdir,%a_scriptdir%
A =%A_AHKVERSION%

ur1:="https://autohotkey.com/download/1.1/version.txt"
SplitPath,ur1, name1, dir1, ext, name_no_ext, drive

gosub,case1   ;- variable
gosub,case2   ;- urldownloadtofile
gosub,case3   ;- wget
return

;-----------------------------------------------

CASE1:
;- CASE-1 Write to variable --------------------
hh:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
ComObjError(false)       ;- doesn't show error
 hh.Silent := True       ;- script failure = off
hh.SetTimeouts(500,500,500,500)
try {
    hh.Open("GET",ur1,true)                                ;Open communication
    hh.Send()                                              ;Send the "get" request
    hh.WaitForResponse()
    aac=
    aac:=hh.ResponseText                                   ;Set the "aac" variable to the response
} catch error {
    xxx:=error.Message
    msgbox, 262208,ERROR ,Error=Catch`n%ur1%`nVariable AAC is empty`n------------------------------------------`n%xxx%`n------------------------------------------,
    }

if aac<>
  {
  msgbox, 262208,AAC ,CASE1=`n%aac%
  return
  }
else
 {
 msgbox, 262208, ,No success`nTry now with UrlDownLoadToFile CASE-2
 return
 }
return


;====================================================
CASE2:
 ;- CASE-2 UrlDownLoadToFile --------------------
f2=%a_scriptdir%\CASE2_%name1%
urldownloadtofile,%ur1%,%f2%
ifexist,%f2%
  msgbox, 262208,UrlDownLoadToFile ,CASE-2`nSee File=%f2%
return
;====================================================



CASE3:
;- CASE-3  Try with WGET  ----------------------
F3 =%a_scriptdir%\%name1%

ifnotexist,%F3%
{
wget1=%a_scriptdir%\wget.exe
ifnotexist,%wget1%
  {
  if A_Is64bitOS
    x1=https://eternallybored.org/misc/wget/current/wget64.exe
  else
    x1=https://eternallybored.org/misc/wget/current/wget.exe
  urldownloadtofile,%x1%,wget.exe
  }
runwait,%comspec% /c wget --no-parent --referer=%dir1% "%ur1%",,hide
}
ifexist,%F3%
  {
  fileread,b,%F3%
  msgbox, 262208,AHK-VERSION ,Latest AHK-VERSION=%b%`nYour    AHK-VERSION=%a_ahkversion%
   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
;====================== end script ==================================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 326 guests