So I did create an check internet script in the past. However it is a bit clunky, and was wondering if there was a more efficient way to continually check the internet, until the internet reconnects:
Code: Select all
UrlDownloadToVar(URL) {
ComObjError(false)
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", URL)
WebRequest.Send()
Return WebRequest.ResponseText
}
#Persistent
SetTimer, CheckInternet, 500
Return
CheckInternet:
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{}
else
{
MsgBox,, Title:Internet status, Text:first check = not working will check again in 2mins & send message, 1
sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:2nd check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
Else
MsgBox,, Title:Internet status, Text:2nd check = not working, 5
sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:3RD check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
else
MsgBox,, Title:Internet status, Text:3rd check = not working, 5
Sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:4th check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
else
MsgBox,, Title:Internet status, Text:5th check = not working, 5
Sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:5th check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
}
else,
Return
}
And this is my telegram script which doesnt seem to work at all. So if someone could advise on how to get this to work, I would really appreciate it
Code: Select all
chatid :=
text := "test message"
param := "chat_id=" chatid "&text=" text
str =https api.telegram.org /botXXXXXXX/sendmessage? Broken Link for safety ;
;msgbox, % url_tovar(str, param) ; this is useful if you need to return data
url_tovar(str, param)
url_tovar(URL, param) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL)
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
WebRequest.Send(param)
res := WebRequest.ResponseText
return res
}