473,320 Members | 1,900 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.

Need to know the LAN connection status

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
Nov 22 '05 #1
5 4613
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" <Ma**@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.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
Nov 22 '05 #2
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" <Ma**@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.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

Nov 22 '05 #3
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" <Ma**@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.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

Nov 22 '05 #4
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" <Ma**@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.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

Nov 22 '05 #5
I hope this does not come to late:
I have the some problem of detecting the NetConnectionStatus inWin2000.
Now I have developed following solution:
First just query the WMI for the required networkadapter, youshould make object containing the Networkadapter andNetworkadapterConfiguration.
In WinXp you can read the ITem "NetConnectionStatus" as known.
In case of Win2000 or Win2003 (you may detect hich OS you areusing be the OperatingSystem-Object, such code is in yourMSDN-Library (getVersion-function that corresponds the OS to theMajor-/Minor versionnumbers) you can examine the Item"IPAdress". In networkadapters (Adapters with a MACAdress orIPEnabled=True) this Item contains the static or dynamikIP-Adress like "120.123.34.0" if there is a physical link. Ifthe 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 knowthere is no link!
I think you never can set the IP-adress of an adapter manualy orprogramatically to 0.0.0.0. Windows won't let you!
Please email me if this helped you Oe***@gmx.net
I'm designing an application that will be run on LAN-connecteddesktop PCs,
and will also be run on laptops that may or may not bedisconnected from the
LAN. The application also needs to continue functioning if thenetwork goes
down.

Looking for code to determine if a LAN connection is presentfirst led me to
Sysytem.Windows.Forms.SystemInformation.Network, but thatappears 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 thoseappear to only
tell you the LAN status at boot-up time. That won't work ifusers unplug, or
if the network goes down.

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

Thanks,
Matt

User submitted from AEWNET (http://www.aewnet.com/)
Nov 22 '05 #6

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

Similar topics

1
by: Savas Ates | last post by:
i have a website... when a user sign up my site sql="UPDATE users set status=1 WHERE userid = '&username&';" but when a user leave my site i want to adjust status as =0 in my database and when...
5
by: Matt | last post by:
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...
2
by: Nico | last post by:
Hello everyone, I have re-formulated the question I asked on my last post:: I am trying to capture the System event raised when a Network Connection is established in VB.NET (ie. connection...
1
by: Agnes | last post by:
in form_load, i will new a sql connection ,fill in the dataset and then close the connection. I use Netstat to check the status. (1)Open the form , The status to the SQL server is "ESTABILISHED"...
3
by: Rahul Anand | last post by:
As per our requirements we have a web service which internally connects (Simple HTTP Post Request) to a remote server to initiate some work. We are calling the web service method asynchronously...
0
by: Arno | last post by:
Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with...
5
by: mivey4 | last post by:
Hi, First off, I am aware that this is a very heavily documented error and I have done my homework for throughly researching probable causes before deciding to post my problem here. At this point,...
3
by: Looch | last post by:
Hi all, Here's the code I'm using: Dim sqlCnn As New SqlConnection(cnn) Dim sqlCmd As New SqlCommand("Update AMS.dbo.Call_Log Set Status = @status, UPSTrack = @ups where TicketNumberActual =...
0
by: Egor Zindy | last post by:
Egor Zindy wrote: #!/usr/bin/env python """ A generic chipid library based on ctypes This module handles most of the functions in FTChipID.dll
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.