tags:

views:

256

answers:

4

Hello,

I want to check if a remote machine is already up (after a reboot/reimage) using C#.

Right now, All I can think of is run a PING command and check if the machine will reply. Are there any elegant ways?

Thanks!

EDIT

One of my concern is that PING usually respond ONCE the machine has started Windows. Some of the services may not have been started by then. See Anders Lindahl answer.

+6  A: 

Considering that PING is essentially designed to do exactly what you're trying to do (see if a machine is available and responding), I'd say it's already pretty elegant. Why complicate things?

Amber
One of my concern is that PING usually respond ONCE the machine has started Windows. Some of the services may not have been started by then. See Anders Lindahl answer.
Ian
Sure. However, the OP didn't state that they were relying on a particular service, but only that they wanted to know if the machine was up. Either way, both answers are useful. :)
Amber
A: 

Why do you think ping is a bad idea? I dont think you will get around sending the host something and check if it responds and there arent really any smaller program than ping that does that. And by using ping you dont have to implement something yourself.

mizipzor
A: 

I don't know about elegant, but depending on (a) some machines can be set to not respond to pings as a potential DoS attack and (b) what kind of access you have to the machine, perhaps a PowerShell script can be of use. PowerShell can be used on an intranet to determine if a machine is powered on, determine state of various machine services, access SQL databases on that machine, bring up/down application services, etc. Again, depending on what you need to do, C# may not be the right tool for the job.

Jarrett Meyer
+1  A: 

Ping is usually enough to verify that a machine has rebooted correctly, but if you are relying on any service on the machine to start up you might want to check that explicitly. Have a look at using WMI to query it:

Anders Lindahl