Batch File to shut down network PC's

Posted on 2009-05-19
Medium Priority
Last Modified: 2013-11-10

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

Question by:rigneydolphin
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 85

Accepted Solution

oBdA earned 2000 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"
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

LVL 70

Expert Comment

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).


Author Comment

ID: 24429524
Thanks, il test these today
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more


Author Comment

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 :-(
LVL 70

Expert Comment

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

Author Closing Comment

ID: 31583108
Got a variation of your solution working.

Thanks for your help

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 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