473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Check if internet is up

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
Aug 30 '06 #1
1 1599
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
<J.*********@Televic.comwrote:
>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
Aug 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
2
by: Kadir CAMOGLU | last post by:
Hi all, I am writing a program with vb.net which getting some information from internet. I must check internet connection before some prosess. But how?
11
by: Sebastian Schöps | last post by:
Hello all, I have to access a website which does a stupid browser check and only accepts Netscape 4.7. The problem is that I have to access the website with Mozilla or Internet Explorer. ...
3
by: Jonny | last post by:
Hi, Please could you tell me how to check for an internet connection in C. I'm using Windows 2000. Many Thanks, Jonny
2
by: Jak Sparrow | last post by:
What are some good ways to programmatically check for software already installed on a computer? For example, to check a version of Internet Explorer, a program can check the registry for the...
2
by: m_laci | last post by:
Hello there, We have encountered a strange error with our ASP.NET applications in combination with SmartNavigation and the setting from Internet Explorer: ‘Check for newer version of pages:...
2
by: Ed Staffin | last post by:
In Internet Explorer under the tools/internet options menu on the general tab, there is a settings button under Temporary internet files. In there the user can specify when to "Check for newer...
7
by: PANGAWD | last post by:
Hi!!! I´m used to search your forum all the time if I have any problem in Java, C, etc,etc... and I always found an answer, but this time I can´t... I know that this must be a simple answer,...
5
by: Ravindra.B | last post by:
I tried checking internet status of my system by issuing ping to some well known server like google.com. But, the problem is that ping is not working if target address is not within the same...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.