Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script: Mass emergency computer shutdown

WinXP Tips

Script: Mass emergency computer shutdown

by  hgate73  Posted    (Edited  )
Our power goes out every week for generator maintenance, and usually we're not given any advanced notice. Users lose important work, and invariably at least one Windows box blows up because of the power loss in the middle of a data write or something.

I wrote this scrip this morning to let me mass-shutdown all of our computers when there's pending power loss. You can set the timeout to whatever you want, as well as the message. It reads a list of computer names (on per line) from names.txt

Code:
:: Author:          --removed--
:: Purpose:         Performs mass shutdown for specified computers
:: Requirements:    1. Run this script with admin privileges
::                  2. Put the names of your computers, one per line, in "names" file in the same directory as this script
:: Version:         1.0 Initial write

:: Prep
:prep
@echo off
title Mass Shutdown
set NAMES_FILE=names.txt
set VERSION=1.0
set TIMER=120
set MESSAGE=Due to generator maintenance, this computer is shutting down in %TIMER% seconds. Save all work and log off immediately.
set TARGET=
cls

:: Menu
:shutdown
echo.
echo  Mass Shutdown script - pretty awesome
echo.
echo  Timeout:    %TIMER%
echo  Names File: %NAMES_FILE%
echo  Message:    %MESSAGE%
echo.
echo  Enter one of the following:
echo    - The IP or name of a computer to shutdown in %TIMER% seconds.
echo    - 'all' to shutdown ALL computers in %NAMES_FILE%. You will be asked to confirm.
echo    - 'abort' to cancel a pending shutdown.
echo    - 'exit' to quit
echo.
:shutdown_loop
@set /P TARGET= Choice:
    if '%TARGET%'=='all' goto shutdown_auto    
    if '%TARGET%'=='abort' goto shutdown_abort
    if '%TARGET%'=='exit' goto end
:: else we assume a target was chosen
shutdown -s -f -m \\%TARGET% -t %TIMER% -c "%MESSAGE%"
set TARGET=
echo.
goto shutdown_loop


:: HIROSHIMA!
:shutdown_auto
title Mass Shutdown
cls
echo.
echo Verify information:
echo.
echo Timeout:    %TIMER%
echo Target:     %TARGET%
echo Names File: %NAMES_FILE%
echo Message:    %MESSAGE%
echo.
echo Ready??
echo.
pause
echo Commencing...
echo.
echo Performing mass shutdown, %TIMER% second countdown.
echo Please wait...
echo.
FOR /F %%i in (%NAMES_FILE%) do shutdown -s -f -m \\%%i -t %TIMER% -c "%MESSAGE%"
goto shutdown

:shutdown_abort
title Abort a mass shutdown
:shutdown_abort_menu
cls
echo.
echo  Enter one of the following:
echo     - The IP or name of a computer to cancel a pending shutdown
echo     - 'all' to cancel a pending mass shutdown.
echo     - 'shutdown' to return to shutdown mode
echo     - 'exit' to quit
echo.
:shutdown_abort_loop
@set /P TARGET= Choice:
    if '%TARGET%'=='all' goto shutdown_abort_auto    
    if '%TARGET%'=='shutdown' goto prep
    if '%TARGET%'=='exit' goto end
:: else we assume a target was chosen
shutdown -a -m \\%TARGET%
set TARGET=
echo.
goto shutdown_abort_loop


:shutdown_abort_auto
FOR /F %%i in (%NAMES_FILE%) do shutdown -a -m \\%%i
goto end

:end
title %USERNAME%
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top