Catchy topic uh? Well I wanted to share my solution so people can tell me if there's anything wrong with it.

There is many solutions to know if the current computer is connected to the internet but none does the job 'correctly'. Here is some info I found on the subject:

1. User Registry: This is the easiest way to check connection. Checking registry value of System\CurrentControlSet\Services\RemoteAccess from HKEY_LOCAL_MACHINE. Using RegOpenKey function from advapi32.dll. Unfortunately, checking is ONLY for MODEM connection. If you are connecting to Internet via Local Area Network (LAN), this method return False even if you are connected

2. Using InternetGetConnectedStateEx: This method use InternetGetConnectedStateEx function from wininet.dll. It works fine, but there is one problem. If your computer is in Local Area Network but you are connecting to Internet via modem, this method always returns True, in case you are connecting to Internet or not

3. Using direct ping to This method use direct ping to some Internet address (URL) and checking for connection errors. Now it use http:/ It's not so quickly, as previous two, but this method is the most reliable

Unfortunately, the third solution, which seemed to be the best one, takes 40 seconds for pinging when not connected. This is too long.

My solution: I am using the winsock control to connect to an ftp (say and if the winsock STATE is not "connected" within the next 4-5 seconds, the computer is not connected to the internet.

Please feel free to add your comment.