Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSee if the computer is connected to the Internet in Visual Basic 2005
DescriptionThis example shows how to see if the computer is connected to the Internet in Visual Basic 2005. This example uses My.Computer.Network.IsAvailable to see if it is connected.
KeywordsMy.Computer.Network.IsAvailable, IsAvailable, Internet, connected, connection, VB.NET
CategoriesInternet, Software Engineering
 
This example uses My.Computer.Network.IsAvailable to see if the network is available and sets a label's text accordingly.
 
If My.Computer.Network.IsAvailable Then
    lblResult.Text = "Connected"
Else
    lblResult.Text = "Not Connected"
End If
 
Joe Sova adds:

This is a complex topic as there are many ways of doing this but none are without side effects.

  • The registry value "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\RemoteAccess" is True if Online but only for modems.
  • InternetGetConnectedState works great if you're not on a Local Area Network (LAN) but if you are on a LAN this will always return True whether you are online or not.
  • A direct ping to a URL is very effective but is very, very slow if there is no connection. Unable to get the "No Connection Timeout" to activate after 5 seconds instead of the default 30-45 seconds!
  • Downloading a webpage is probably the most effective but it is quite awkward.

    Thanks Joe!

    I think the problem is the disconnected philosophy of the Internet. The assumption is that a network link may disappear at any time. It makes the network robust but makes it hard to know whether the network is gone or just slow.

  •  
     
    Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
      Updated