×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

WinXP Tips

Script: Mass emergency computer shutdown by hgate73
Posted: 17 Apr 10

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%

Back to Microsoft: Windows FAQ Index
Back to Microsoft: Windows Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close