0

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"
Else
 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

Edited by Nick Evan: Fixed formatting

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by GeekByChoiCe
0
If My.Computer.Network.IsAvailable then
         MsgBox("Network detected!")
      Else
         MsgBox("Network connection is not found!")
      End If
1

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.

Votes + Comments
+
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.