1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

To Check Internet Connection

Posted at

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
}

Alt Result

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?