To see if the machine is connected to the internet, the following functions would be useful.
I have experienced that the InternetGetConnectedState API function sometimes returned true right after the router started rebooting. So it would help to double-check the connection with WMI Ping.
CheckInternetConnection.ahk
; Press F1 to check the internet connection.
F1::
if IsOnline() && Ping("www.google.com")
TrayTip, Internet Connection, Online, 5, 1
else
TrayTip, Internet Connection, Offline, 5, 1
Return
Ping(nAddress, strComputer=".") {
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
colPings := objWMIService.ExecQuery("Select StatusCode From Win32_PingStatus where Address = '" nAddress "'")
For objStatus in colPings
If (objStatus.StatusCode = "") || (objStatus.StatusCode != 0)
Return False
Else
Return True
}
IsOnline() {
if DllCall("Wininet.dll\InternetGetConnectedState", "Str", "0x40", "Int", 0)
Return True
else
Return False
}