Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. how can i check my network is connected

how can i check my network is connected

Scheduled Pinned Locked Moved Visual Basic
sysadminhelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Your Code
    wrote on last edited by
    #1

    how can i check my network is connected, pleaae help me, thanks kevil

    L B S 3 Replies Last reply
    0
    • Y Your Code

      how can i check my network is connected, pleaae help me, thanks kevil

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      Y 1 Reply Last reply
      0
      • Y Your Code

        how can i check my network is connected, pleaae help me, thanks kevil

        B Offline
        B Offline
        Briga
        wrote on last edited by
        #3

        If you're under VS2005/FW2 then it's very easy. There's a specific Application event that pop ups whenever network connection status changes.

        1 Reply Last reply
        0
        • L Lost User

          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

          Y Offline
          Y Offline
          Your Code
          wrote on last edited by
          #4

          please, i need more help, can yuo give me sample kevil

          L 1 Reply Last reply
          0
          • Y Your Code

            please, i need more help, can yuo give me sample kevil

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • Y Your Code

              how can i check my network is connected, pleaae help me, thanks kevil

              S Offline
              S Offline
              Steve Pullan
              wrote on last edited by
              #6

              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 the MyApplication 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 :-)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups