-
Jan 3rd, 2013, 10:54 PM
#1
Thread Starter
Addicted Member
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
-
Jan 3rd, 2013, 11:04 PM
#2
Thread Starter
Addicted Member
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.
-
Jan 4th, 2013, 12:38 AM
#3
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
-
Jan 4th, 2013, 01:12 AM
#4
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.
-
Jan 4th, 2013, 02:27 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|