dcsimg
Results 1 to 5 of 5

Thread: How to access network information directly from Window's Network tray icon's source.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2010
    Posts
    148

    How to access network information directly from Window's Network tray icon's source.

    I looking for a way to check to see if the internet is available. My current method is to ping a popular site like Google. However, I notice that sometimes when I lose my internet connection, a message indicating that the internet is not available appears on my network tray icon. Is there anyway to access that information directly?

    Thank you,
    Adrian

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2010
    Posts
    148

    Re: How to access network information directly from Window's Network tray icon's sour

    I suppose that the system.net.networkinginformation namespace is used...just not sure how.

  3. #3
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: How to access network information directly from Window's Network tray icon's sour

    try this:
    Code:
        Private Sub frmTestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                   AddHandler Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged, AddressOf OnNetWorkChange
    
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
    
            End Try
        End Sub
        Private Sub OnNetWorkChange(ByVal sender As Object, ByVal e As System.Net.NetworkInformation.NetworkAvailabilityEventArgs)
              Try
                If e.IsAvailable = False Then
                    MessageBox.Show("Network is disconnected")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    __________________
    Rate the posts that helped you

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,567

    Re: How to access network information directly from Window's Network tray icon's sour

    It's important to recognise that there's a difference between network availability and internet access. If you have a separate modem and router and you switch off your modem then your network is available because the router is the centre of the network but you have no internet access because your modem is your gateway to the internet. You'll note that the Windows tray icon distinguishes the three different states, i.e. no network, network but no internet, and both.

    The NetworkAvailabilityChanged event is about the network, not the internet. I don't know for sure but I would guess that Windows defines internet access as being whether it can ping a DNS server. As far as I'm aware, there is no dedicated managed interface for that. You'd have to either ping the system-registered DNS servers yourself or else find some unmanaged way to access Windows own information, which would likely involve WMI. WMI is exposed to managed code via the System.Management namespace.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2010
    Posts
    148

    Re: How to access network information directly from Window's Network tray icon's sour

    Thank you both for replying to my post.

    The "network but no internet" is what I'm looking for.

    If that information is not available directly, one improvement, I guess, is to ping the DNS server instead of Google.

    Thanks again.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width