I have a problem when trying to detect the computers network connection status. Here is the code I have used:

Dim IsAvalible As String = My.Computer.Network.IsAvailable

If IsAvalible = True Then 
Label1.Text = "Connected"
 If IsAvalible = False Then I
    Label1.Text = "Disconnected"
End If
End If

But for some even when the network is disconnected or the computers wifi is turned on I still get the result of "Connected". I think there something wrong with the code. Could someone help me please ? Thank You

Recommended Answers

All 2 Replies

If My.Computer.Network.IsAvailable then
         MsgBox("Network detected!")
         MsgBox("Network connection is not found!")
      End If

Thing is, if you are behind a router then you have always a network available.
try this instead:

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Int32, ByVal dwReserved As Int32) As Boolean

Public Shared Function IsConnectedToInternet() As Boolean
	Dim Desc As Int32
	Return InternetGetConnectedState(Desc, 0)
End Function

This will return the real status.

commented: + +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.