best method for detecting live net connection

I have an app that sits in the system tray and automatically downloads data with http periodically.

The problem is that of course sometimes modem users aren't logged on to the net.  In this case, with some users (including some AOL Users), this http activity will try to force the users to log in (pop up either dial-up net or AOL login screen).  So, what I need is the best method possible to see if there is a net connection without actually having an impact on the system.

Who is Participating?
intheConnect With a Mentor Commented:
Hi kdw:

try this:

//note i added Wininet to the uses section.

procedure TForm1.Button1Click(Sender: TObject);
   dwConnectionTypes: dWord;
dwConnectionTypes := 0;
if InternetGetConnectedState(@dwConnectionTypes, 0) then
  showmessage('not connected');

if that fails to work you can use the component here: 

though i suggest the best method of all would be to ping a known address ( etc)using a ping component (you can get one from f.piette's site)

Regards Barry
kdwAuthor Commented:
inthe, here is a question.  Using the ping method, do you have to use an IP address?  I've got a friend tell me that using a domain name with the ping has the same problem of starting the net connection when it does the hostname lookup.

If so, is there anything such as an IP address that will almost always be alive?
if you get f.piettes ping component look at the demo "pingtst" ,it converts a web address "" to a ip address then trys to ping it.
if it comes back DnsLookupDone and has erro <> 0 then the host was not resolved
(you know here that you are most likely not online)
you should ping about at least  3-4 different address like,, etc..
becuase sometimes the pings timeout will activate before the ping is made it to the ip address.if you use 3-4 at least 1 will get through and if none get through you can safely assume your not online whearas only one ping needs to make it and you know your online for sure..
therefore you dont need a ip addess just giving it a web address should be sufficent and i have no problems with it trying to logon if im not logged on already ..
note i also use aol and no problems ..
you dont have to use ping but it pronbably the safest way to be sure ..
did you try the
one ?
it works for me also ..
kdwAuthor Commented:
Thanks for the help.  Went for the Ping method and looks like it is working well so far.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.