Remote Shutdown Batch File

  • Thread starter Thread starter DavidB
  • Start date Start date
D

DavidB

I use the "shutdown \\computername" command within a batch
file to remotely restart all the machines in our office.
If a user shuts down their machine and the batch file is
ran, the batch file hangs when it encounters the machine
that's shutdown. This use to not happen under NT. We're
currently using Windows 2000 SP-4. is there any way to
avoid this?
 
Maybe pinging the computer before issuing the shutdown ...

Assuming the env variable 'Machine' contains the name of
the machine that is to be tested, something like this
might work for you ...

ping -n 1 %Machine% | find "TTL=" > nul && (
shutdown \\%Machine%)

Tom Lavedas
===========
 
Does it hang forever? I've tried to shutdown machines that were already off
before, and it'll eventually indicate that it couldn't connect and move on.
You could loop through a 'net view' and shut down those machines to avoid
this slow down most of the time.

Ray at work
 
I run this batch file at night using the task scheduler.
If Phil could give an example of some code that would
first test weather a machine is on. If so, perform the
shutdown command, else go to the next line in my batch
file. Any help on this would be greatly appreciated.
David B
 
It worked great! Thanks Tom
-----Original Message-----
Maybe pinging the computer before issuing the shutdown ...

Assuming the env variable 'Machine' contains the name of
the machine that is to be tested, something like this
might work for you ...

ping -n 1 %Machine% | find "TTL=" > nul && (
shutdown \\%Machine%)

Tom Lavedas
===========


.
 
DavidB said:
I run this batch file at night using the task scheduler.
If Phil could give an example of some code that would
first test weather a machine is on. If so, perform the
shutdown command, else go to the next line in my batch
file. Any help on this would be greatly appreciated.
David B

If you use shutdown from NT reskit, there might be differences.
Reskit for w2k isn't free, the one for w2k3 seens to be.

An superior alternative to shutdown is psshutdown from:
http://www.sysinternals.com/ntw2k/freeware/psshutdown.shtml
Except from redistribution its free.
I just tested the behavior for computer off the power in w2ksp4.
I get an errormessage "Couldn't access COMPUTERNAME"

hth
 
DavidB said:
I run this batch file at night using the task scheduler.
If Phil could give an example of some code that would
first test weather a machine is on. If so, perform the
shutdown command, else go to the next line in my batch
file. Any help on this would be greatly appreciated.
David B

Hi David

One approach that would work...

ping -n 1 somecomputer >nul && shutdown \\somecomputer

Jens
 
Back
Top