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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.