Win32 API InternetGetConnectedState

Ido Samuelson over on the DotNetJunkies blogs posts this useful P/Invoke snippet to check whether a client has an active Internet connection:

[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

public
static bool
IsConnected()
{
 
int connectionDescription = 0;
 
return InternetGetConnectedState(out connectionDescription, 0);
}

Wininet.dll comes standard with Internet Explorer 4.0 and higher.

Also, don't forget to import System.Runtime.InteropServices, of course. ;-)

No Comments