Davidyese Posted Monday at 05:59 PM Posted Monday at 05:59 PM Hi All, There is a problem in my code as it will return incorrect return value with download link, inspite other URL return correct if anyone can help and write code to validate Url here is my code : #NoTrayIcon ;$sUrl = "https://githubx.com/ip7z/7zip/releases/download" ; >>> Return Correct Return Value $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" ; >>> Return InCorrect Return Value ;$sUrl = "https://www.google.com" ; >>> Return Correct Return Value If _CheckUrlAlive($sUrl) Then MsgBox(64+262144, "Success", "URL is alive") Else MsgBox(16+262144, "Error", "URL is dead or inaccessible") EndIf Func _CheckUrlAlive($sUrl) Local $ONERRORHANDLER = ObjEvent("AutoIt.Error", "_TIMED_ERRFUNC") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False $oHTTP.Open("HEAD", $sUrl, False) ; Use HEAD to avoid downloading the file $oHTTP.Send() Local $iStatus = $oHTTP.Status Return $iStatus ; 200 = OK, 301/302 = Redirect (still alive) Return ($iStatus >= 200 And $iStatus <= 400) EndFunc Func _TIMED_ERRFUNC($ONERRORHANDLER) ConsoleWrite($ONERRORHANDLER.description) EndFunc ;==>_TIME_ERRFUNC Thanks in advance
Solution argumentum Posted Monday at 06:33 PM Solution Posted Monday at 06:33 PM #include <MsgBoxConstants.au3> Global $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" If _CheckUrlAlive($sUrl) Then MsgBox($MB_ICONINFORMATION + $MB_SYSTEMMODAL, "Success", "URL is alive: " & @extended) Else MsgBox($MB_ICONERROR + $MB_SYSTEMMODAL, "Error", "URL is dead or inaccessible") EndIf Func _CheckUrlAlive($sUrl) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects (Option 6) and HTTPS-to-HTTP transitions (Option 12) $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("HEAD", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status Return SetError(0, $iStatus, ($iStatus >= 200 And $iStatus < 400)) EndFunc Func _COMErrorFunc() ; This function runs automatically if a COM error occurs ConsoleWrite("COM Error Intercepted!" & @CRLF) Return EndFunc 🤔 Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted Monday at 06:40 PM Posted Monday at 06:40 PM ..or just get the file ? expandcollapse popup#include <MsgBoxConstants.au3> Local $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" Local $sSavePath = @ScriptDir & "\7z2600-x64.exe" If _DownloadBinaryFile($sUrl, $sSavePath) Then MsgBox($MB_ICONINFORMATION, "Success", "File downloaded successfully to:" & @CRLF & $sSavePath) Else MsgBox($MB_ICONERROR, "Error", "Failed to download the file.") EndIf Func _DownloadBinaryFile($sUrl, $sFileName) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects for GitHub CDN $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("GET", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status If $iStatus >= 200 And $iStatus < 400 Then ; Use ResponseBody for binary files like .exe Local $vBinaryData = $oHTTP.ResponseBody ; Open file in Binary mode (16) + Overwrite (2) = 18 Local $hFile = FileOpen($sFileName, 18) If $hFile = -1 Then Return False FileWrite($hFile, $vBinaryData) FileClose($hFile) Return True EndIf Return False EndFunc Func _COMErrorFunc() Return ; Ignore errors to let script handle them via @error EndFunc Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Davidyese Posted Monday at 06:41 PM Author Posted Monday at 06:41 PM 7 minutes ago, argumentum said: #include <MsgBoxConstants.au3> Global $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" If _CheckUrlAlive($sUrl) Then MsgBox($MB_ICONINFORMATION + $MB_SYSTEMMODAL, "Success", "URL is alive: " & @extended) Else MsgBox($MB_ICONERROR + $MB_SYSTEMMODAL, "Error", "URL is dead or inaccessible") EndIf Func _CheckUrlAlive($sUrl) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects (Option 6) and HTTPS-to-HTTP transitions (Option 12) $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("HEAD", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status Return SetError(0, $iStatus, ($iStatus >= 200 And $iStatus < 400)) EndFunc Func _COMErrorFunc() ; This function runs automatically if a COM error occurs ConsoleWrite("COM Error Intercepted!" & @CRLF) Return EndFunc 🤔 Thanks for reply but this code return incorrect value as the download link is Ok & Alive working this code return : Error : Dead or inaccessible URL
Davidyese Posted Monday at 06:46 PM Author Posted Monday at 06:46 PM (edited) 6 minutes ago, argumentum said: ..or just get the file ? expandcollapse popup#include <MsgBoxConstants.au3> Local $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" Local $sSavePath = @ScriptDir & "\7z2600-x64.exe" If _DownloadBinaryFile($sUrl, $sSavePath) Then MsgBox($MB_ICONINFORMATION, "Success", "File downloaded successfully to:" & @CRLF & $sSavePath) Else MsgBox($MB_ICONERROR, "Error", "Failed to download the file.") EndIf Func _DownloadBinaryFile($sUrl, $sFileName) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects for GitHub CDN $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("GET", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status If $iStatus >= 200 And $iStatus < 400 Then ; Use ResponseBody for binary files like .exe Local $vBinaryData = $oHTTP.ResponseBody ; Open file in Binary mode (16) + Overwrite (2) = 18 Local $hFile = FileOpen($sFileName, 18) If $hFile = -1 Then Return False FileWrite($hFile, $vBinaryData) FileClose($hFile) Return True EndIf Return False EndFunc Func _COMErrorFunc() Return ; Ignore errors to let script handle them via @error EndFunc This code gives an Error message : Failed to download the file so not working with me Edited Monday at 06:46 PM by Davidyese
argumentum Posted Monday at 06:49 PM Posted Monday at 06:49 PM ..worked for me. Are you blocked in the area were you live ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Nine Posted Monday at 06:52 PM Posted Monday at 06:52 PM 1 minute ago, argumentum said: worked for me Works also for me (with HEAD verb). Some sites have security block against excessive accesses. Try in 24 hours. argumentum and Davidyese 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Davidyese Posted Monday at 06:56 PM Author Posted Monday at 06:56 PM (edited) 7 minutes ago, argumentum said: ..worked for me. Are you blocked in the area were you live ? Saudi Arabia i can use internet settings to adjust so what is the countery that could help the code to work ??? Edited Monday at 06:57 PM by Davidyese
argumentum Posted Monday at 06:57 PM Posted Monday at 06:57 PM (edited) ..and a hash checker for github: expandcollapse popup#include <MsgBoxConstants.au3> Local $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" Local $sHash = _GetGitHubAssetHash($sUrl) If $sHash Then ConsoleWrite(@CRLF & $sHash & @CRLF) MsgBox($MB_ICONINFORMATION, "Found Hash", "Official SHA-256 Digest:" & @CRLF & $sHash) Else MsgBox($MB_ICONERROR, "Error", "Could not retrieve hash from GitHub API.") EndIf Func _GetGitHubAssetHash($sUrl) ; Parse the URL to get owner, repo, and tag Local $aMatch = StringRegExp($sUrl, "github\.com/([^/]+)/([^/]+)/releases/download/([^/]+)/([^/]+)", 3) If UBound($aMatch) < 4 Then Return "" Local $sOwner = $aMatch[0], $sRepo = $aMatch[1], $sTag = $aMatch[2], $sFile = $aMatch[3] ; Build the API URL for this release Local $sApiUrl = "https://api.github.com/repos/" & $sOwner & "/" & $sRepo & "/releases/tags/" & $sTag Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.Open("GET", $sApiUrl, False) ; GitHub API requires a User-Agent header $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)") ; Use a real browser string ? $oHTTP.Send() If @error Then ConsoleWrite("Network Error: Could not connect to GitHub. Check your ISP/VPN." & @CRLF) Return SetError(1, @ScriptLineNumber, "") EndIf If $oHTTP.Status = 403 Then ConsoleWrite("Rate Limit Exceeded! Check: https://github.com" & @CRLF) Return SetError(2, @ScriptLineNumber, "") EndIf If $oHTTP.Status <> 200 Then Return SetError(3, @ScriptLineNumber, "") ; Use Regex to find the 'digest' for our specific filename in the JSON response ; Recent GitHub releases include a "digest" field for each asset Local $sResponse = $oHTTP.ResponseText Local $sPattern = '"name"\s*:\s*"' & $sFile & '".*?"digest"\s*:\s*"([^"]+)"' Local $aHashMatch = StringRegExp($sResponse, $sPattern, 3) If UBound($aHashMatch) > 0 Then Return $aHashMatch[0] Return SetError(4, @ScriptLineNumber, "") EndFunc Edited Monday at 07:08 PM by argumentum better Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted Monday at 06:58 PM Posted Monday at 06:58 PM (edited) Am in the US. But if a VPN don't work, what @Nine said is true too. GitHub API has a rate limit (usually 60 requests per hour for unauthenticated users). Edited Monday at 07:01 PM by argumentum Davidyese 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Davidyese Posted Monday at 07:24 PM Author Posted Monday at 07:24 PM 10 minutes ago, argumentum said: Am in the US. But if a VPN don't work, what @Nine said is true too. GitHub API has a rate limit (usually 60 requests per hour for unauthenticated users). Thanks my dear for your help maybe my countery has some restrictions to some websites but it's Okay, i found another simpler solution to check the mentioned links before especially : download links here is the code but unfortunately it takes long time with some dead website like this dead link : "https://githubx.com/ip7z/7zip/releases/download" the new simple code work with me perfectly 100% and i hope it will help anyone else #NoTrayIcon Local $TestURL = "https://githubx.com/ip7z/7zip/releases/download" ;Local $TestURL = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" ;Local $TestURL = "https://www.google.com" ;Local $TestURL = "https://www.googlarsds.com" Local $Timer = TimerInit() If _UrlAlive($TestURL) Then Local $Diff = Int(TimerDiff($Timer)) MsgBox(64+262144, "Success", "URL is alive" & " [ " & Round($Diff / 1000, 3) & " ]" ) Else Local $Diff = Int(TimerDiff($Timer)) MsgBox(16+262144, "Error", "URL is dead or inaccessible" & " [ " & Round($Diff / 1000, 3) & " ]" ) EndIf Exit Func _UrlAlive($sUrl) Return Not (InetRead($sUrl, 1) == "") ; 1 = Force reload from remote EndFunc argumentum 1
Davidyese Posted yesterday at 05:56 AM Author Posted yesterday at 05:56 AM (edited) On 4/13/2026 at 8:40 PM, argumentum said: #include <MsgBoxConstants.au3> Global $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" If _CheckUrlAlive($sUrl) Then MsgBox($MB_ICONINFORMATION + $MB_SYSTEMMODAL, "Success", "URL is alive: " & @extended) Else MsgBox($MB_ICONERROR + $MB_SYSTEMMODAL, "Error", "URL is dead or inaccessible") EndIf Func _CheckUrlAlive($sUrl) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects (Option 6) and HTTPS-to-HTTP transitions (Option 12) $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("HEAD", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status Return SetError(0, $iStatus, ($iStatus >= 200 And $iStatus < 400)) EndFunc Func _COMErrorFunc() ; This function runs automatically if a COM error occurs ConsoleWrite("COM Error Intercepted!" & @CRLF) Return EndFunc ..or just get the file ? expandcollapse popup#include <MsgBoxConstants.au3> Local $sUrl = "https://github.com/ip7z/7zip/releases/download/26.00/7z2600-x64.exe" Local $sSavePath = @ScriptDir & "\7z2600-x64.exe" If _DownloadBinaryFile($sUrl, $sSavePath) Then MsgBox($MB_ICONINFORMATION, "Success", "File downloaded successfully to:" & @CRLF & $sSavePath) Else MsgBox($MB_ICONERROR, "Error", "Failed to download the file.") EndIf Func _DownloadBinaryFile($sUrl, $sFileName) Local $oMyError = ObjEvent("AutoIt.Error", "_COMErrorFunc") Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") If Not IsObj($oHTTP) Then Return False ; Enable redirects for GitHub CDN $oHTTP.Option(6) = True $oHTTP.Option(12) = True $oHTTP.Open("GET", $sUrl, False) $oHTTP.Send() If @error Then Return False Local $iStatus = $oHTTP.Status If $iStatus >= 200 And $iStatus < 400 Then ; Use ResponseBody for binary files like .exe Local $vBinaryData = $oHTTP.ResponseBody ; Open file in Binary mode (16) + Overwrite (2) = 18 Local $hFile = FileOpen($sFileName, 18) If $hFile = -1 Then Return False FileWrite($hFile, $vBinaryData) FileClose($hFile) Return True EndIf Return False EndFunc Func _COMErrorFunc() Return ; Ignore errors to let script handle them via @error EndFunc It's Working with me now after correcting some proxy internet settings Thanks alot my dear : argumentum Edited yesterday at 06:25 AM by Davidyese argumentum 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now