@echo off if "%~1" == "" echo No command line given && goto :HELP :: Time limit for PING in milliseconds. Feel free to change set TIMELIMIT=200 :: Path to the executable, no need to set it, if the PATH variable contains a path to it set RS2PATH=RShutdown2.exe :: Empty initial command line set RS2CMDLINE= set NAMELIST= :: BLOCK - parse the command line intended for RShutdown2 :ContinueParsing if /i "%~1" == "" goto :DoneParsing :: If a list with machine names was given, extract it and don't pass on to RShutdown2 if /i "%~1" == "/file" ( set NAMELIST=%~2 shift shift goto :ContinueParsing ) set RS2CMDLINE=%RS2CMDLINE% %~1 :: Next parameter shift goto :ContinueParsing :DoneParsing if "%NAMELIST%" == "" ( echo Executing: %RS2PATH%%RS2CMDLINE% %RS2PATH%%RS2CMDLINE% goto :EOF ) if not EXIST "%NAMELIST%" echo The file "%NAMELIST%" (with machine names) does not exist & goto :EOF for /f "tokens=*" %%i in (%NAMELIST%) do @( ping -n 1 -w %TIMELIMIT% %%i > NUL if "%ERRORLEVEL%" == "0" ( echo Executing: %RS2PATH%%RS2CMDLINE% /machine %%i %RS2PATH%%RS2CMDLINE% /machine %%i ) else ( echo Timeout for machine: %%i - could not send shutdown request! ) ) goto :EOF :HELP echo. echo Syntax: echo rsd2ex.cmd ^ echo. echo This script relays the command line to RShutdown2, but filters the list with echo the file names. Then the script will see whether the command line gave a list echo of machines in a text file, if so it pings each of the machines before it echo attempts a shutdown request - which is done only if the machine could be echo reached by PING. echo.