Check if internet is up

J

Janiek Buysrogge

Hi,

I'm using the following code to check if there is a connection to the
internet:

#region
//Creating the extern function...
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int
Description, int ReservedValue);
#endregion

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int Desc;
bool res = InternetGetConnectedState(out Desc, 0);

Console.WriteLine("Inet is up: " + res);
}

The strange thing is that it always returns false, even as I am
writing this message and while browsing the web.

I am connected to the internet via LAN in my company. Maybe this
function is more aimed at modem users ?

Is there any clarification for this ?

Thanks,

JB
 
J

Janiek Buysrogge

Hello,

Now I'm using the following code, seems to work:

Solution:

#region
[DllImport("wininet.dll")]
private extern static bool InternetCheckConnection(string
Description, int Flags, int ReservedValue);
#endregion

public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
int Desc;
bool res = InternetCheckConnection("http://www.google.be",
1, 0);

Console.WriteLine("Inet is up: " + res);
}

JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top