PC Review


Reply
Thread Tools Rate Thread

Check if internet is up

 
 
Janiek Buysrogge
Guest
Posts: n/a
 
      30th Aug 2006
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
 
Reply With Quote
 
 
 
 
Janiek Buysrogge
Guest
Posts: n/a
 
      30th Aug 2006
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

On Wed, 30 Aug 2006 15:15:59 +0200, Janiek Buysrogge
<(E-Mail Removed)> wrote:

>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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if i'm connected to the internet =?Utf-8?B?Sm9obg==?= Microsoft Excel Programming 3 12th Jun 2007 05:25 AM
Internet Explorer PC Time check vs Mozilla PC Time check different =?Utf-8?B?S29uIENlcm4=?= Windows XP General 1 4th May 2005 01:20 PM
Internet Connection Check? David Pope Microsoft Dot NET Compact Framework 5 16th Mar 2005 11:18 AM
RE: Check out this internet package Charles Kenyon Microsoft Word New Users 0 4th Oct 2003 08:56 AM
Check this internet pack -z Microsoft Access Form Coding 1 27th Sep 2003 11:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:30 AM.