I intend to use the code below to shutdown or restart a computer. Every time I run this, it goes back to set /p var=Type computer name here: Can you please tell me, what is wrong with my script and how to fix it?
@ECHO off
set /p var=Type computer name here:
cls
TITLE %var% power control!!!!
ECHO Copyright © Joshua Reynolds 2012
ECHO USE THIS PROGRAM AT YOUR OWN RISK
pause
:start
cls
ECHO Choose an option below:
ECHO 1. Shutdown
ECHO 2. Restart
ECHO 3. Abort previous choice
ECHO 4. Exit
set /p choice=Type the options number:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto shutdown
if '%choice%'=='2' goto restart
if '%choice%'=='3' goto abort
if '%choice%'=='4' exit
cls
ECHO "%choice%" is not a valid option please try again
ECHO.
pause
goto start
:shutdown
COLOR 4f
cls
ECHO To shutdown %var%
pause
shutdown /s /m \\%var%
ECHO %var% should now shutdown.
goto start
:restart
COLOR A0
cls
ECHO To restart %var%
pause
shutdown /r /m \\%var%
ECHO %var% should now restart.
goto end
:abort
COLOR 5f
cls
shutdown /a /m \\%var%
goto end
:end
pause
COLOR 0f
goto start
Perhaps the name of your batch script is shutdown.bat and it is in your current directory. So when your script tries to run the SHUTDOWN command, it re-runs your batch script instead.
Either change the name of your script, or else explicitly use
shutdown.exewithin your script whenever you want to invoke the command.