Solved

Batch File to shut down network PC's

Posted on 2009-05-19
6
800 Views
Last Modified: 2013-11-10
Hi,

I'm trying to create a batch file to shutdown all out network PC's after 12.30 am every night. I created a simple batch file which parses an IP address from a text file then sends a remote shutdown command to that IP address.

This works fine but if the command comes to an IP address of a PC that is already switched off it ties up the batch file for an exorbitant amount of time. (Code below)

I would prefer to add some method to check if the PC is on first then issue the remote shutdown command if PING returns a response.

Any body have any ideas on this?
FOR /F %%i IN (computers.txt) DO shutdown -m \\%%i -f -s -t 300 -c "Remote PC Shutdown in progress"

Open in new window

0
Comment
Question by:rigneydolphin
  • 3
  • 2
6 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 24424168
You can ping them before you run the shutdown command, or you could use "start" (the latter will for a short time open a bunch of command windows). You can of course combine the both as well, but there's not much to be gained.


Example 1:
 
FOR /F %%i IN (computers.txt) DO (
  ping %%i | find /i "TTL"
  if not errorlevel 1 shutdown.exe -m \\%%i -f -s -t 300 -c "Remote PC Shutdown in progress"
)
 
Example2:
 
FOR /F %%i IN (computers.txt) DO (
  start "" shutdown.exe -m \\%%i -f -s -t 300 -c "Remote PC Shutdown in progress"
)
 
Example 3:
 
FOR /F %%i IN (computers.txt) DO (
  ping %%i | find /i "TTL"
  if not errorlevel 1 start "" shutdown.exe -m \\%%i -f -s -t 300 -c "Remote PC Shutdown in progress"
)

Open in new window

0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24426194
If you use
start /b "" shutdown .... ^& exit /b
instead of start, no additional windows will appear (but the one-and-only console window output is a mess).


0
 

Author Comment

by:rigneydolphin
ID: 24429524
Thanks, il test these today
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:rigneydolphin
ID: 24472488
thanks for your suggestions, can't manage to get any of these to work so going to purchase software instead i think. its taking too long to get it sorted :-(
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24473178
That's true only when you know of software doing this ... Don't underestimate the effort for searching for and testing software!
0
 

Author Closing Comment

by:rigneydolphin
ID: 31583108
Got a variation of your solution working.

Thanks for your help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question