Need to know the LAN connection status

Need to know the LAN connection status

am 25.10.2004 23:19:02 von matt

I'm designing an application that will be run on LAN-connected desktop PCs,
and will also be run on laptops that may or may not be disconnected from the
LAN. The application also needs to continue functioning if the network goes
down.

Looking for code to determine if a LAN connection is present first led me to
Sysytem.Windows.Forms.SystemInformation.Network, but that appears to only
tell you if a valid NIC is in the machine.... worthless.

I next checked out the following API calls: IsConnected, GetConnectedState,
IsNetworkAlive and InternetGetConnectedState. All of those appear to only
tell you the LAN status at boot-up time. That won't work if users unplug, or
if the network goes down.

Windows has the ability to know when a LAN connection is present, because
the little icon in the taskbar shows the correct status. How can I get VB.Net
to be that aware? I'd be happy to query whatever data drives the little
taskbar icon, if I have to...

Thanks,
Matt

Re: Need to know the LAN connection status

am 26.10.2004 11:03:22 von Shiva

Using WMI is one option:

ManagementObjectSearcher ms = new ManagementObjectSearcher ("SELECT
NetConnectionStatus FROM Win32_NetworkAdapter");
foreach (ManagementObject mo in ms.Get())
{
if (mo["NetConnectionStatus"] != null)
{
Console.WriteLine(mo["NetConnectionStatus"]);
}
}

Please note that this works from Win XP onwards.

"Matt" wrote in message
news:161583D5-D7B9-4AD9-9F49-18141078D0A5@microsoft.com...
I'm designing an application that will be run on LAN-connected desktop PCs,
and will also be run on laptops that may or may not be disconnected from the
LAN. The application also needs to continue functioning if the network goes
down.

Looking for code to determine if a LAN connection is present first led me to
Sysytem.Windows.Forms.SystemInformation.Network, but that appears to only
tell you if a valid NIC is in the machine.... worthless.

I next checked out the following API calls: IsConnected, GetConnectedState,
IsNetworkAlive and InternetGetConnectedState. All of those appear to only
tell you the LAN status at boot-up time. That won't work if users unplug, or
if the network goes down.

Windows has the ability to know when a LAN connection is present, because
the little icon in the taskbar shows the correct status. How can I get
VB.Net
to be that aware? I'd be happy to query whatever data drives the little
taskbar icon, if I have to...

Thanks,
Matt

Re: Need to know the LAN connection status

am 26.10.2004 14:41:08 von HenrikNordgren

One possibility is to create two flows in the application, and use exceptions
to control it. I use that for one app I have written that uses webservices...
if I get an exception indicating the webservice can't be reached, catch it
and perform alternate tasks in the catch statement...

kind regards
henrik

"Shiva" wrote:

> Using WMI is one option:
>
> ManagementObjectSearcher ms = new ManagementObjectSearcher ("SELECT
> NetConnectionStatus FROM Win32_NetworkAdapter");
> foreach (ManagementObject mo in ms.Get())
> {
> if (mo["NetConnectionStatus"] != null)
> {
> Console.WriteLine(mo["NetConnectionStatus"]);
> }
> }
>
> Please note that this works from Win XP onwards.
>
> "Matt" wrote in message
> news:161583D5-D7B9-4AD9-9F49-18141078D0A5@microsoft.com...
> I'm designing an application that will be run on LAN-connected desktop PCs,
> and will also be run on laptops that may or may not be disconnected from the
> LAN. The application also needs to continue functioning if the network goes
> down.
>
> Looking for code to determine if a LAN connection is present first led me to
> Sysytem.Windows.Forms.SystemInformation.Network, but that appears to only
> tell you if a valid NIC is in the machine.... worthless.
>
> I next checked out the following API calls: IsConnected, GetConnectedState,
> IsNetworkAlive and InternetGetConnectedState. All of those appear to only
> tell you the LAN status at boot-up time. That won't work if users unplug, or
> if the network goes down.
>
> Windows has the ability to know when a LAN connection is present, because
> the little icon in the taskbar shows the correct status. How can I get
> VB.Net
> to be that aware? I'd be happy to query whatever data drives the little
> taskbar icon, if I have to...
>
> Thanks,
> Matt
>
>
>

Re: Need to know the LAN connection status

am 26.10.2004 16:05:02 von matt

Shiva,

Thanks for the prompt response. Unfortunately, I'm working on Win2000 PCs
here, so this won't help me currently.

"Shiva" wrote:

> Using WMI is one option:
>
> ManagementObjectSearcher ms = new ManagementObjectSearcher ("SELECT
> NetConnectionStatus FROM Win32_NetworkAdapter");
> foreach (ManagementObject mo in ms.Get())
> {
> if (mo["NetConnectionStatus"] != null)
> {
> Console.WriteLine(mo["NetConnectionStatus"]);
> }
> }
>
> Please note that this works from Win XP onwards.
>
> "Matt" wrote in message
> news:161583D5-D7B9-4AD9-9F49-18141078D0A5@microsoft.com...
> I'm designing an application that will be run on LAN-connected desktop PCs,
> and will also be run on laptops that may or may not be disconnected from the
> LAN. The application also needs to continue functioning if the network goes
> down.
>
> Looking for code to determine if a LAN connection is present first led me to
> Sysytem.Windows.Forms.SystemInformation.Network, but that appears to only
> tell you if a valid NIC is in the machine.... worthless.
>
> I next checked out the following API calls: IsConnected, GetConnectedState,
> IsNetworkAlive and InternetGetConnectedState. All of those appear to only
> tell you the LAN status at boot-up time. That won't work if users unplug, or
> if the network goes down.
>
> Windows has the ability to know when a LAN connection is present, because
> the little icon in the taskbar shows the correct status. How can I get
> VB.Net
> to be that aware? I'd be happy to query whatever data drives the little
> taskbar icon, if I have to...
>
> Thanks,
> Matt
>
>
>

Re: Need to know the LAN connection status

am 26.10.2004 16:09:05 von matt

Henrik,
Thanks for the prompt response. I was afraid I might have to let it fall to
an exception. I wanted to avoid the delay and proactively get the status, as
opposed to waiting for an exception. If I was on XP, I would use the great
suggestion Shiva had and use WMI. As it is, I can use
InternetGetConnectedState for the people who are booting up unplugged, and
let an exception handle the situation where the LAN goes down. Thanks for
your help.

"Henrik Nordgren" wrote:

> One possibility is to create two flows in the application, and use exceptions
> to control it. I use that for one app I have written that uses webservices...
> if I get an exception indicating the webservice can't be reached, catch it
> and perform alternate tasks in the catch statement...
>
> kind regards
> henrik
>
> "Shiva" wrote:
>
> > Using WMI is one option:
> >
> > ManagementObjectSearcher ms = new ManagementObjectSearcher ("SELECT
> > NetConnectionStatus FROM Win32_NetworkAdapter");
> > foreach (ManagementObject mo in ms.Get())
> > {
> > if (mo["NetConnectionStatus"] != null)
> > {
> > Console.WriteLine(mo["NetConnectionStatus"]);
> > }
> > }
> >
> > Please note that this works from Win XP onwards.
> >
> > "Matt" wrote in message
> > news:161583D5-D7B9-4AD9-9F49-18141078D0A5@microsoft.com...
> > I'm designing an application that will be run on LAN-connected desktop PCs,
> > and will also be run on laptops that may or may not be disconnected from the
> > LAN. The application also needs to continue functioning if the network goes
> > down.
> >
> > Looking for code to determine if a LAN connection is present first led me to
> > Sysytem.Windows.Forms.SystemInformation.Network, but that appears to only
> > tell you if a valid NIC is in the machine.... worthless.
> >
> > I next checked out the following API calls: IsConnected, GetConnectedState,
> > IsNetworkAlive and InternetGetConnectedState. All of those appear to only
> > tell you the LAN status at boot-up time. That won't work if users unplug, or
> > if the network goes down.
> >
> > Windows has the ability to know when a LAN connection is present, because
> > the little icon in the taskbar shows the correct status. How can I get
> > VB.Net
> > to be that aware? I'd be happy to query whatever data drives the little
> > taskbar icon, if I have to...
> >
> > Thanks,
> > Matt
> >
> >
> >

Re: Need to know the LAN connection status

am 21.04.2005 11:31:54 von guest

I hope this does not come to late:
I have the some problem of detecting the NetConnectionStatus in=
Win2000.
Now I have developed following solution:
First just query the WMI for the required networkadapter, you=
should make object containing the Networkadapter and=
NetworkadapterConfiguration.
In WinXp you can read the ITem "NetConnectionStatus" as known.
In case of Win2000 or Win2003 (you may detect hich OS you are=
using be the OperatingSystem-Object, such code is in your=
MSDN-Library (getVersion-function that corresponds the OS to the=
Major-/Minor versionnumbers) you can examine the Item=
"IPAdress". In networkadapters (Adapters with a MACAdress or=
IPEnabled=3DTrue) this Item contains the static or dynamik=
IP-Adress like "120.123.34.0" if there is a physical link. If=
the Adapter is disconnected than the networkcard sets its IP to=
"0.0.0.0" even if in the windows-registry still "120.123.34.0"=
is valid.
So if the IPAdress you get from the WMI is "0.0.0.0" you know=
there is no link!
I think you never can set the IP-adress of an adapter manualy or=
programatically to 0.0.0.0. Windows won't let you!
Please email me if this helped you Oez.Y@gmx.net

> I'm designing an application that will be run on LAN-connected=
desktop PCs,
> and will also be run on laptops that may or may not be=
disconnected from the
> LAN. The application also needs to continue functioning if the=
network goes
> down.
>
> Looking for code to determine if a LAN connection is present=
first led me to
> Sysytem.Windows.Forms.SystemInformation.Network, but that=
appears to only
> tell you if a valid NIC is in the machine.... worthless.
>
> I next checked out the following API calls: IsConnected,=
GetConnectedState,
> IsNetworkAlive and InternetGetConnectedState. All of those=
appear to only
> tell you the LAN status at boot-up time. That won't work if=
users unplug, or
> if the network goes down.
>
> Windows has the ability to know when a LAN connection is=
present, because
> the little icon in the taskbar shows the correct status. How=
can I get VB.Net
> to be that aware? I'd be happy to query whatever data drives=
the little
> taskbar icon, if I have to...
>
> Thanks,
> Matt
User submitted from AEWNET (http://www.aewnet.com/)