• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Helpe needed with Script

I need help creating a script to do the following:

reboot & force apps that are hung closed on weekdays at around 11PM. I want to be able to control which machines this executed on by manipulating a text file that will hold the  host names.

Thank you.
2 Solutions
SHUTDOWN -r -f -t 01

thats the command from MSDODS prompt.

-r) reboot
-f) force close apps
-t 1) wait 1 second

Please refer to this MS reference for the reboot command:


You could alternatively:

SHUTDOWN -r -f -t 01 -m \\computername

This will restart a computer remotely if it's part of a workgroup or domain and has NetBIOS up and running.
If you want to do reboot multiple computers I would recommend to use the PsShutdown tool from the Microsoft's Sysinternals Suite - is freeware, will not need an install to the "admin PC" from where you will shutdown remoteley all the required PC's/Servers and the most important thing - it will allow you to set the HOUR:MINUTE at which to execute the shutdown command - the "normal" shutdown command from operating system will allow to set the INTERVAL (in seconds) from the current time before will do the shutdown which is pretty hard to calculate if you want to run the command NOW to be executed at 11 PM.

So the command witl be like this:

PSSHUTDOWN @ComputerList.txt -r -f -t 23:00

For more options for PSSHUTDOWN command see the download link mentioned above.
Steve KnightIT ConsultancyCommented:
To add to the first post you can do that wth multiple entries in a rtext file with a for loop:

@echo off
for /f "tokens=*" %%a in ('type serverlist.txt') do SHUTDOWN -r -f -t 01 -m \\%%a

If using  from command line rather than batch file (don't call it shutdown.cmd or it will be a big loop...) change the %% for single %


Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Use dragon-it's batch file to be run by a schedules task, at 11PM every day.

Also, If you call it directly from a scheduled task, without a batch file, use only one % as described by dragon-it, include the full path of "serverlist.txt", and between double quots " if it includes spaces.

for /f "tokens=*" %a in ('type "C:\Batch Files\serverlist.txt"') do SHUTDOWN -r -f -t 01 -m \\%a

Another version would be:
for /f "usebackq delims=" %a in ("C:\Batch Files\serverlist.txt") do SHUTDOWN -r -f -t 1 -m \\%a

Steve KnightIT ConsultancyCommented:
good points.  also of course make sure scheduled with rights to shutdown other workstations, e.g. Domain admin a/c or given the required user rights on those machines security polcieisy and ntfs perms to serverlist file
And by the way, it's better to use a local or domain account that will have limmited rights to perform a scheduled task on a PC that will run a batch file. That gives unlimmited power to a knolwdgable user, my modifying the batch file.
Steve KnightIT ConsultancyCommented:
true, as suggested would only really need the user right in security to shutdown which could be added using a group policy most easily.

PberSolutions ArchitectCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now