[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

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

news.microsoft.com

9/10/2003 6:35:00 PM

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


8 Answers

msnews.microsoft.com

9/10/2003 6:53:00 PM

0

"Steven Van Dyke" <svandyke@rft.com> wrote in message
news:utYo0o8dDHA.2640@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
john.saunders@surfcontrol.com


news.microsoft.com

9/10/2003 8:36:00 PM

0

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" <john.saunders@surfcontrol.com> wrote in message
news:ebfDlz8dDHA.2524@TK2MSFTNGP09.phx.gbl...
> "Steven Van Dyke" <svandyke@rft.com> wrote in message
> news:utYo0o8dDHA.2640@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
> john.saunders@surfcontrol.com
>
>


msnews.microsoft.com

9/10/2003 8:42:00 PM

0

"Steven Van Dyke" <svandyke@rft.com> wrote in message
news:uz62Vs9dDHA.576@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
john.saunders@surfcontrol.com


news.microsoft.com

9/10/2003 8:58:00 PM

0

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" <john.saunders@surfcontrol.com> wrote in message
news:%234BkXw9dDHA.1944@TK2MSFTNGP12.phx.gbl...
> "Steven Van Dyke" <svandyke@rft.com> wrote in message
> news:uz62Vs9dDHA.576@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
> john.saunders@surfcontrol.com
>
>


Andrea Zani

9/10/2003 9:02:00 PM

0

> 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/InternetGetConnectedS...

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


msnews.microsoft.com

9/10/2003 9:06:00 PM

0

"Steven Van Dyke" <svandyke@rft.com> wrote in message
news:%23rU%23o49dDHA.2328@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
john.saunders@surfcontrol.com


news.microsoft.com

9/10/2003 10:35:00 PM

0

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" <andrew@aspitalia.com> wrote in message
news:bjo4e0$l8of0$3@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/InternetGetConnectedS...
>
> 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
>
>


news.microsoft.com

9/10/2003 10:39:00 PM

0

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" <andrew@aspitalia.com> wrote in message
news:bjo4e0$l8of0$3@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/InternetGetConnectedS...
>
> 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
>
>