You need to use the InternetGetConnectedState API, here is a small example I have which I porbably downloaded a long time ago from someone somewhere, or made myself - Honestly, I cannot remember :
...