Check to see if a pc is on before attempting file.copy

  • Thread starter Thread starter RvGrah
  • Start date Start date
R

RvGrah

I've built a small app to deploy my apps in a small domain, just for
my own use when I make small updates to pass to my end users. My app
uses File.Copy, and works fine except that it takes a long time to
fail if the machine I'm copying to is in standby, turned off or
hibernating etc.

How could I determine if the machine is running *before* I try
File.Copy? A ping method maybe?

Thanks, Bob
 
RvGrah said:
I've built a small app to deploy my apps in a small domain, just for
my own use when I make small updates to pass to my end users. My app
uses File.Copy, and works fine except that it takes a long time to
fail if the machine I'm copying to is in standby, turned off or
hibernating etc.

How could I determine if the machine is running *before* I try
File.Copy? A ping method maybe?

The client should copy the files from the server to itself when they next
run the app.

Michael
 
The client should copy the files from the server to itself when they next
run the app.

Michael

So you'd write a launcher that would check for a new version before
the main app runs? I haven't heard of doing that. I'm assuming the app
can't replace itself? If you (or anyone else) have a bit more guidance
I'd appreciate it.

Bob
 
RvGrah said:
So you'd write a launcher that would check for a new version before
the main app runs? I haven't heard of doing that. I'm assuming the app
can't replace itself? If you (or anyone else) have a bit more guidance
I'd appreciate it.

The way I did it was for the app to be initially installed as per a normal
install (keeping things as close to normal is a Good Thing(tm)). Then when
the customer wished to upgrade your app they should install an update on the
server only. Possibly there should be a check at that time to ensure no one
is using the app or have some way to kick them out. Then as your app is run
on each client machine the app itself should do an initial check to see if
it needs updating. If it does then it should download a seperate program
from the server that will perform the update. The main app should then quit
to allow the update program to proceed. The update program can then copy
files over from the server to the client.

The advantage of this is that you have complete freedom in updating the
update program. Otherwise, say, version 11 will need to be working with
version 10's update program or possibly even an older version. The other
option is to just have the update program being the installer. Yet another
option is to use an MSI with active directory but I'm a bit vague on that
method. There's also ClickOnce deployment but I'm not too familiar with that
either.

Michael
 
There's a new class in 2.0 called System.Net.NetworkInformation that
exposes fast and easy methods to ping a machine by host name. Here's a
little thing I modified from the help files that did just what I
wanted:



private void TryPing(string myHost, string myUser)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();

// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;

// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(myHost, timeout, buffer,
options);
if (reply.Status == IPStatus.Success)
{
//htHosts is a hashtable of users and their machines names
htHosts.Add(myUser, myHost);
}
else
{
<snip: here I add to a list of unavailable machines>
}

}
 
RvGrah said:
There's a new class in 2.0 called System.Net.NetworkInformation that
exposes fast and easy methods to ping a machine by host name. Here's a
little thing I modified from the help files that did just what I
wanted:

I don't think that's going to help because the ping could fail for various
reasons but the filecopy would still work.

Michael
 
Back
Top