Google Answers Logo
View Question
Q: Using vb to find out if the computer is on the internet ( Answered,   2 Comments )
Subject: Using vb to find out if the computer is on the internet
Category: Computers
Asked by: faith16-ga
List Price: $5.00
Posted: 07 Apr 2003 09:21 PDT
Expires: 07 May 2003 09:21 PDT
Question ID: 187186
Using vb7 how do you find out if the computer is on the internet?

Clarification of Question by faith16-ga on 07 Apr 2003 13:31 PDT
Hi, i tried the api mentioned in the topic but haven't managed to get this to work
Subject: Re: Using vb to find out if the computer is on the internet
Answered By: theta-ga on 08 Apr 2003 01:51 PDT
Hi faith16-ga,
    Finding out the status of the computer's network connection status
is a fairly popular need with developers, and you'd think that there
would be a method in .NET to provide this information. Unfortunately,
.NET contains no in built method to detect and provide this
information. So, here are some tricks developers use to find out the
computers connection status:
- [1] Ping a valid IP address.
   This appears to be the most foolproof method of checking the
connection status. Be sure to use a valid IP address (say insted of a domain name (say, since
using a domain name will cause the computer to start dialling the
network service provider if the computer is not connected. It will
also cause problems with dial-up internet connection sharing (the
"server" system will dial whenever one of the client systems does any
of these types of calls). And you don't want that, since it will
irritate your users no end.
  There are a couple of methods you can use to ping an IP address:
       - Use the WMI(Windows Management Instrumentation)
Win32_PingStatus class
         As specified in the below mentioned ExpertsExchange question,
this require only two lines of code. Here is the code...
      dim x as new"Win32_PingStatus.Address=''")
         as given on this page:
             - ExpertsExchange: pinging an IP using .NET framework
        For more information on the Win32_PingStatus WMI class and its
return values, see the following MSDN Library article:
             - MSDN : Platform SDK: WMI > Win32_PingStatus
       -  Another way to ping an IP address is by using the System.Net
classes. You can find example code in the following newsgroup threads:
             - Subject: Ping in
               Newsgroup: microsoft.public.dotnet.languages.vb
             - Subject: Can anyone convert this C# sample to VB.NET?
               Newsgroup: microsoft.public.dotnet.languages.vb

- [2] Use the InternetGetConnectedState() Win32 API function (also
suggested by hammer-ga in his comment)
  Unfortunately, the InternetGetConnectedState() API(available with IE
4 and above) is not entirely reliable. It's exact functioning varies
with the version of IE installed, and in certain cases, it may be
unable to detect an internet connection, even when the computer is
  For more information, please check out the following articles:
      - MSKB Article 315035: The InternetGetConnectedState Function
Returns FALSE When Connected to the Internet
      - MSKB Article 242558: Detecting If You Have a Connection to the
      - InternetGetConnectedState Event Handler

- [3] Try connecting to a website/webpage (as also suggested by
sgtcory-ga in his comment)
  This method unfortunately suffers from the dialling problem that I
mention while discussing the ping method. Every time you try to check
your online status this way, it will cause the host computer to dial
if it is not online.
  See the following newsgroup thread:
     - Subject: How to detect internet connection?
       Newsgroup: microsoft.public.dotnet.framework.windowsforms

- [4] Check the computer's local IP address. If this address is the
loopback address ( then the machine is not connected to a
network. Please see the following newsgroup post for the required
VB.NET code:
       - Subject: Internet connection detect 
         Newsgroups: microsoft.public.dotnet.languages.vb
      Unfortunately, this method is also not foolproof. It will give
you an incorrect result if the user is on a network without being
connected to the Internet.


Hope this helps.

If you need any clarifications, just ask!


Google/Google Groups Search Terms Used:
  detect internet connection
  using ping to detect internet connection
Subject: Re: Using vb to find out if the computer is on the internet
From: hammer-ga on 07 Apr 2003 10:43 PDT
You can use the InternetGetConnectedState API that is installed with
IE4 and higher. A full module that you can cut-and-paste is available


Also see the Related links on this page for several other methods of
testing various network states.

I have not posted this as an answer, because I don't have a .Net test
environment available and the code is marked for VB6. I believe it
will also work with .Net.

- Hammer
Subject: Re: Using vb to find out if the computer is on the internet
From: sgtcory-ga on 07 Apr 2003 18:43 PDT
Not even sure if you are developing in this capacity, but this may be
an alternative :


I'll keep looking for you, but much like hammer, I don't have a .NET
test environment.


Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy