0

我打算使用下面的代码来关闭或重新启动计算机。每次我运行它时,它都会回到set /p var=Type computer name here:你能告诉我,我的脚本有什么问题以及如何修复它吗?

@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
4

1 回答 1

1

也许您的批处理脚本的名称是shutdown.bat,它位于您的当前目录中。因此,当您的脚本尝试运行 SHUTDOWN 命令时,它会重新运行您的批处理脚本。

要么更改脚本的名称,要么shutdown.exe在要调用命令时在脚本中显式使用。

于 2012-11-10T22:39:20.223 回答