0
votes

I am getting an error when I run the code below, please help me to run the code properly :)

enter image description here

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$sFile = _DownloadFile('https://cdn.pixabay.com/photo/2013/06/25/22/09/rose-141314_960_720.jpg')
    shellExecute($sFile)
Func _DownloadFile($sURL)
Local $hDownload, $sFile
$sFile = StringRegExpReplace($sURL, "^.*/", "")
$sDirectory = @TempDir & $sFile
$hDownload = InetGet($sURL, $sDirectory, 17, 1)
InetClose($hDownload)
Return $sDirectory
EndFunc; == >_GetURLImage
1
What happens on W7? - Bookeater
It was permission error on temp directory :))) - f0xtr0d

1 Answers

1
votes

It actually worked fine on my system, but I can tell you what went wrong. You passed the fourth parameter of InetGet as 1 ($INET_DOWNLOADBACKGROUND) which means the download of the is carried out in the background, and the script continues executing. The next command in your function is to close the handle returned by InetGet, but the AutoIt documentation is clear on what happens when you do this to a download that has yet to complete - the download will be cancelled.

Therefore, simply change the last parameter you send to the InetGet function to 0 and it should work. Or you can use InetGetInfo to check if the download has completed.