473,325 Members | 2,342 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,325 software developers and data experts.

is local pc online?

hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon

Nov 14 '06 #1
7 3272
Hi Gideon,

If you are planning on trying to connect to the computer once you are sure
it's online, then don't bother checking first. Just try the operation and
catch the appropriate exception that indicates the computer could not be
reached.

If you need to know whether a computer is online for informational purposes
then you have some options.

If you're sure that the computer will honor ping requests, then you can use
the Ping class in the 2.0 framework:

System.Net.Network.Ping ping
= new System.Net.NetworkInformation.Ping();

System.Net.NetworkInformation.PingReply reply
= ping.Send("Machine Name");

Console.WriteLine(reply.Status); // You want "Success"

If you're using an earlier version of the framework or if Ping won't work for
you then you can try to access a known share on the computer (you must have
the appropriate permissions to read the share):

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("\\\\Machine
Name\\C$");

Console.WriteLine(dir.Exists);

Another option is to try connecting a socket to a port that you know is open.

Realize that there is no way to be certain whether the computer is offline.
If all of these cases fail then you can just assume the computer is offline,
but it might just be that it's not responding to any of these particular
requests.

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon

Nov 14 '06 #2
Under .NET 2 :
System.Net.NetworkInformation.NetworkInterface.Get IsNetworkAvailable()

I'm sure there is a NetworkAvailable property on something in .NET 1 but
dont have it on my machine here so cant check for you.

Ciaran O'Donnell
"Dave Sexton" wrote:
Hi Gideon,

If you are planning on trying to connect to the computer once you are sure
it's online, then don't bother checking first. Just try the operation and
catch the appropriate exception that indicates the computer could not be
reached.

If you need to know whether a computer is online for informational purposes
then you have some options.

If you're sure that the computer will honor ping requests, then you can use
the Ping class in the 2.0 framework:

System.Net.Network.Ping ping
= new System.Net.NetworkInformation.Ping();

System.Net.NetworkInformation.PingReply reply
= ping.Send("Machine Name");

Console.WriteLine(reply.Status); // You want "Success"

If you're using an earlier version of the framework or if Ping won't work for
you then you can try to access a known share on the computer (you must have
the appropriate permissions to read the share):

System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("\\\\Machine
Name\\C$");

Console.WriteLine(dir.Exists);

Another option is to try connecting a socket to a port that you know is open.

Realize that there is no way to be certain whether the computer is offline.
If all of these cases fail then you can just assume the computer is offline,
but it might just be that it's not responding to any of these particular
requests.

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
hi,

i'm making a netowork based app. and if i have the UNC path to a local
computer is there a way i can check whether the pc is online/offline??

Gideon


Nov 14 '06 #3
Hi Ciaran,
Under .NET 2 :
System.Net.NetworkInformation.NetworkInterface.Get IsNetworkAvailable()
That may work for the local computer but it doesn't help the OP find out if a
different computer is online.
I'm sure there is a NetworkAvailable property on something in .NET 1 but
dont have it on my machine here so cant check for you.
AFAIK there is no managed equivalent in earlier framework versions.

--
Dave Sexton
Nov 14 '06 #4
hi ,

thanks for repying , i'm sorry i was'nt specific.. i'm using C# and
..NET 2 ....
i'm kaing a booking application for a hotel . .. and there one main pc
with a set of local pcs connected to it. The database fr the customers
is on the main pc.

basicaly i hav a listview that should have icons (pc icons) .. for
local pcs connected to it (the main pc ,lets call it server)
Now there (hopefully) will be an add function tht brings a
BrowseFrFolder dialog and allows the user to add a path. When this is
done . .the application is kinda intalled on this (client) local pc ..
..and the client then connects to the "server" for the database (this
should happen all via th UNC path) ....

Now.. .everytime the listview loads .. i wanna check whether the
ADDED pcs are offline or on and depending on that.. i want the icon to
be coloured or black and white.

I thought of doing what dave said in the first place... but was'nt
exactly sure.. .i'm new to C#...

and Dave , what do u mean by :
Dave Sexton wrote:
That may work for the local computer but it doesn't help the OP find out if a
different computer is online.
problem is i dont have a network here to test it all out i have to goto
a cyber cafe to test it.. and i cant do that often (it costs)

Thanks so much

Gideon

Nov 14 '06 #5
Hi Gideon,

Thanks for the background information.

<snip>
I thought of doing what dave said in the first place... but was'nt
exactly sure.. .i'm new to C#...
You should speak to the network administrator to see if there is a common port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.

There might be some other means to verify whether a computer is online or
offline within the context of a LAN. Active Directory is one LAN tool that
may be of help to you if it's already in use on the target network.

There are network protocols that can be used on a LAN to determine whether
computers are available. These protocols might provide a port that you can
query to check for connectivity.

If you can't find some common check point amongst all computers on the network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.
and Dave , what do u mean by :
Dave Sexton wrote:
>That may work for the local computer but it doesn't help the OP find out if
a
different computer is online.
The example that was supplied can be used to determine whether there is a
network connection available on the local computer only. It won't help you to
determine the status of other computers on the network.

<snip>

--
Dave Sexton
Nov 14 '06 #6
HI ,

i'm making an application for a simple hotel , theres no network
administrator , and the people who are going to use my software are
simple accoutants or data enterers! lol

anyway... i' think i'll use directory.Exists() to see if the path to
the pc is valid and then chaning the lisview's picture! basically if is
it unavailiable i want to remove/Disable some of the context menu
options!

i looked a little into pinging and active directory , i might use them
later on!

thanks for your help!

Gideon

Dave Sexton wrote:
You should speak to the network administrator to see if there is a common port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.
If you can't find some common check point amongst all computers on the network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.
Nov 17 '06 #7
Hi Gideon,

Are you just assuming that certain computers on the LAN might not be available
at times or are there good reasons for computer's to be offline? Are you just
concerned with network instability?

The network should probably be stable and configured properly so that all
computers are "available" at all times.

Showing the users that the computers are "available" may not help them if they
should always be available anyway. Also, it's possible that your method of
detection may show the computer as available until your application attempts
an operation that requires a connection to the remote computer, in which case
it fails and leaves the user wondering why your program said that it wouldn't
fail.

Also realize that most users would probably like to try the operation
themselves, even if your program states that the computer is probably offline.

From the information you've supplied it sounds to me like you shouldn't notify
the users of a computer's availability in the list and just assume that it
will be available at all times. If an attempted operation fails, you may want
to alert the user that the computer may be offline and to try again later.
Then, you may want to show an offline icon in the list next to the computer
name, but this shouldn't prevent your program from attempting the operation
again when the user demands it. If a subsequent attempt succeeds, you can
remove the offline icon.

This way the user decides when your program should try the operation, keeping
the user in control. And if they don't have that ability and somehow "fix"
the offline problem themselves, they'll have to wait for your program to
update the display before they can try again.

If you have a good reason for certain computers to be unavailable at times and
you think it would be better to absolutely prevent users from attempting an
operation on a remote computer that your program assumes will fail, then
you'll have to use a timer to periodically check the computer's availability
and update your display. The easiest and most light-weight approach to
determining whether a computer is online, IMO, is the Ping class. You can use
the System.Timers.Timer class in code to raise a periodic, synchronized event
at the interval you specify.

HTH

--
Dave Sexton

"giddy" <gi*******@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
HI ,

i'm making an application for a simple hotel , theres no network
administrator , and the people who are going to use my software are
simple accoutants or data enterers! lol

anyway... i' think i'll use directory.Exists() to see if the path to
the pc is valid and then chaning the lisview's picture! basically if is
it unavailiable i want to remove/Disable some of the context menu
options!

i looked a little into pinging and active directory , i might use them
later on!

thanks for your help!

Gideon

Dave Sexton wrote:
>You should speak to the network administrator to see if there is a common
port
open or share accessible on every computer on the network, or if every
computer can be configured to respond to Ping requests, for example.
>If you can't find some common check point amongst all computers on the
network
then you might find that the list you are trying to provide in your program
may not be a good representation of whether the computers are reachable or
not, and so might not be much help to the user.

Nov 17 '06 #8

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

Similar topics

3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
195
by: Torbjørn Pettersen | last post by:
As you might have noticed I'm trying to clean up my web site's HTML code. The way I do it is simply more or less redoing to complete site, testing it on a web server I have set up on my local...
4
by: John Morgan | last post by:
I have Enterprise Manager on my local machine. For the last twelve months it has been connecting without problem to my online SQL Server database provided by my ISP. Three weeks ago the ISP...
1
by: Aliza Klein | last post by:
Hi. A client of mine has a website with a standard "Contact Us" form page with name, address etc. The information is currently sent via email to the client and is then data entered into their...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
3
by: RLN | last post by:
(New to SQL Server Installs) I installed SQL Server 2005 Developer Edition on a WinXP-SP2 workstation and can see some enterprise databases on the network just fine. My problem is I cannot...
3
by: John Morgan | last post by:
I have my first small SQl Server 2005 database developed on my local server and I have also its equivalent as an online database. I wish to update the local database (using and asp.net interface)...
11
by: cj | last post by:
Perhaps someone knows how to do this. When I open a new ASP.NET web service application in VS 2008, it opens with a simple Hello World web service already written. I want to see this work. ...
1
by: ll | last post by:
Hi, I have copied a MS SQL database to my local machine and am testing it with ASP pages, locally, on IIS. I have a db connect page that keeps the current connections for the live database. My...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a app that uses several membership/role providers. I can list these Providers with the code: Dim rootWebConfig1 As Configuration rootWebConfig1 =...
0
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...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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
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.