how can i check my network is connected
-
Hi! You can use the sensapi.dll of the internet explorer to check if the network is been connected: Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long This is the API declaration to access the IsNetworkAlive function within the sensapi.dll. So, just use it like this: Dim llReturn as Long IF IsNetworkAlive(llReturn) = 0 THEN ' Not connected code ELSE ' ... Your code (if connected) End If If you need more help, just let me know! Marcel Erz -- modified at 2:44 Tuesday 13th December, 2005
-
Hi! You can use the sensapi.dll of the internet explorer to check if the network is been connected: Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long This is the API declaration to access the IsNetworkAlive function within the sensapi.dll. So, just use it like this: Dim llReturn as Long IF IsNetworkAlive(llReturn) = 0 THEN ' Not connected code ELSE ' ... Your code (if connected) End If If you need more help, just let me know! Marcel Erz -- modified at 2:44 Tuesday 13th December, 2005
-
Hi! Here an other example:
Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long Private Const NETWORK_ALIVE_LAN = &H1 ' LAN connection Private Const NETWORK_ALIVE_WAN = &H2 ' RAS connection(for internet) Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim llReturn As Long If IsNetworkAlive(llReturn) = 0 Then MessageBox.Show("Your system is not connected!") Else If (llReturn And NETWORK_ALIVE_LAN) = NETWORK_ALIVE_LAN Then MessageBox.Show("Your system is connected to the LAN" + _ " (may be over router to internet too)!") End If If (llReturn And NETWORK_ALIVE_WAN) = NETWORK_ALIVE_WAN Then MessageBox.Show("Your system is connected to the WAN by any" + _ " kind of modem direct connected to you system!") End If End If End Sub
If you need more help, just let me know! Marcel Erz -
It has been mentioned that .NET Framework 2.0 has the smarts to do this. Here's a brief rundown on what is required. I found the basis for this post at The Occasionally Connected Application[^]. I just setup a simple one-form app which had one label on it. The label is changed to "Connected" or "Not Connected" depending on the state of the network. The initial state is detected via this code in the
Form_Load
event ...Private Sub Form1\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If My.Computer.Network.IsAvailable = True Then lblConnectedStatus.Text = "Connected" Else lblConnectedStatus.Text = "Not Connected" End If End Sub
Now we need to dynamically test the connection state. This is done by creating an event handler for the
NetworkAvailabilityChanged
in theMyApplication
class ...Private Sub MyApplication\_NetworkAvailabilityChanged(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged If e.IsNetworkAvailable = True Then My.Forms.Form1.lblConnectedStatus.Text = "CONNECTED" Else My.Forms.Form1.lblConnectedStatus.Text = "Not Connected" End If End Sub
This passed most of the unplug / disable tests. Use this in conjunction with the new Ping functions in 2.0 and you may have a viable solution. ...Steve "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once :-)