468,119 Members | 1,690 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

How to: Determine if you have a Network Connection???

Hi

I need a code snippet to determine if my computer is connected to a network
or not.

There's probably a System.Net function for it, but I cannot find it.

Thanks,

Steve
Nov 17 '05 #1
8 2014
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi

I need a code snippet to determine if my computer is connected to a network or not.

There's probably a System.Net function for it, but I cannot find it.


You probably want to get a bit more specific. For instance, do you care
_which_ network it's connected to? Would a home network with just one
printer on it be as useful to you as being connected to the Internet?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #2
This is an app for work. It needs to gain access to other computers on the
network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine names
on the network. If I'm not connected, I just put the local machine name in
the combo box. My only issue is, how do I easily determine if I have a
connection or not?

Steve

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi

I need a code snippet to determine if my computer is connected to a

network
or not.

There's probably a System.Net function for it, but I cannot find it.


You probably want to get a bit more specific. For instance, do you care
_which_ network it's connected to? Would a home network with just one
printer on it be as useful to you as being connected to the Internet?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #3
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
This is an app for work. It needs to gain access to other computers on the
network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine names on the network. If I'm not connected, I just put the local machine name in
the combo box. My only issue is, how do I easily determine if I have a
connection or not?


I think I'd just try it and find out. If it fails, just put the local
machine name in the box. If it succeeds, put all of them there. This will
also take care of the case where you're connected to the network, but some
other problem prevents you from getting the list of machine names.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #4
Hi,

Thanks for your response. I'm using the API call NetServerEnum. When my
network cable is plugged in, it succeeds, and returns all of my network
computer names. When the cable is disconnected, it still succeeds, returning
just 1 computer name "sv-file". I was hoping it would either fail, or return
zero entries. I didn't think it would be a good idea to say "if (count > 1)
then connected..."

I'm not sure why "sv-file" still appears in the list. Any thoughts on the
best solution?

Steve

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:uz*************@tk2msftngp13.phx.gbl...
This is an app for work. It needs to gain access to other computers on the network. It does NOT need to get on the Internet. Basically, If I'm
connected to a network, I populate a combo box with all of the machine

names
on the network. If I'm not connected, I just put the local machine name in the combo box. My only issue is, how do I easily determine if I have a
connection or not?


I think I'd just try it and find out. If it fails, just put the local
machine name in the box. If it succeeds, put all of them there. This will
also take care of the case where you're connected to the network, but some
other problem prevents you from getting the list of machine names.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #5
"Steven Van Dyke" <sv******@rft.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Hi,

Thanks for your response. I'm using the API call NetServerEnum. When my
network cable is plugged in, it succeeds, and returns all of my network
computer names. When the cable is disconnected, it still succeeds, returning just 1 computer name "sv-file". I was hoping it would either fail, or return zero entries. I didn't think it would be a good idea to say "if (count > 1) then connected..."

I'm not sure why "sv-file" still appears in the list. Any thoughts on the
best solution?


Is sv-file your computer? If not, then I have no idea. Is it the domain
controller or something? With the cable disconnected, are you able to do
"NET VIEW \\SV-FILE"? How about when it's connected?
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #6
> Hi

I need a code snippet to determine if my computer is connected to a network or not.

There's probably a System.Net function for it, but I cannot find it.

Thanks,

Steve


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ
Nov 17 '05 #7
Thanks for your response. I tried your code snippet. It seems to return the
same Descrizione value of 18 whether my network cable is connected or not.
So, it doesn't seem to solve my problem.

Steve
"Andrea Zani" <an****@aspitalia.com> wrote in message
news:bj************@ID-192116.news.uni-berlin.de...
Hi

I need a code snippet to determine if my computer is connected to a

network
or not.

There's probably a System.Net function for it, but I cannot find it.

Thanks,

Steve


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ

Nov 17 '05 #8
Hi,

I tried your solution. It seems to return the same Descrizione value of 18
whether my network card cable is connected or not. So, this doesn't help my
problem.

There must be some simple function that can determine if there is a live
network cable plugged into my network card. Any other suggestions?

Steve

"Andrea Zani" <an****@aspitalia.com> wrote in message
news:bj************@ID-192116.news.uni-berlin.de...
Hi

I need a code snippet to determine if my computer is connected to a

network
or not.

There's probably a System.Net function for it, but I cannot find it.

Thanks,

Steve


Read this document:
http://www.mentalis.org/apilist/Inte...tedState.shtml

And read this example (author Cangiano):

using System ;
using System.Runtime ;
using System.Runtime.InteropServices ;

public class ConnectionState
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( int out
Description, int ReservedValue ) ;

public static bool IsConnected( ){
int Descrizione ;
return InternetGetConnectedState( out Descrizione, 0 ) ;}
}

Bye
--
AZ

Nov 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Kamus of Kadizhar | last post: by
8 posts views Thread by codecraig | last post: by
8 posts views Thread by MrNobody | last post: by
25 posts views Thread by _DD | last post: by
13 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.