In application like Messenger or
Application that provides automatic update need to check that user is connected
to internet or not before proceeding further.
so we need to check whether he is connected to internet or not we can check
that with use of WIN32 API.
we can use Win32 API Wininet.dll 'sInternetGetConnectedState()
method to check Internet Status
for working with Pinvoke we need to add name space
using System.Runtime.InteropServices;
now we need to write prototyping of the function like below
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(outint connectionDescription, int reservedValue);
Now simply we can use this function to check internet
connectivity
take one button and label on form In buttons's click even write following code
private void btnCheckConnection_Click(objectsender, EventArgs e)
{
int Description=0;
bool isConnected = InternetGetConnectedState(out Description, 0);
if (isConnected == true)
{
label1.Text = "User is Connected to Internet ";
}
else
{
label1.Text = "Disconnected";


sankar narayananPosted Aug 18, 2010, 3:36 AM
Hi Buddy, This code only check LAN avail or not , not an internet Thanks, Sankar B