Link to home
Start Free TrialLog in
Avatar of bahti1777
bahti1777

asked on

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.
Avatar of Adrian Sluijters
Adrian Sluijters
Flag of United Kingdom of Great Britain and Northern Ireland image

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:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/shutdown.mspx?mfr=true

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.
ASKER CERTIFIED SOLUTION
Avatar of Lucian Constantin
Lucian Constantin
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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.
true, as suggested would only really need the user right in security to shutdown which could be added using a group policy most easily.

Steve
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.