第二次执行命令失败

第二次执行命令失败

当我运行此文件并选择选项 1,然后再次选择选项 1。他运行 sfc /scannow 命令。但是当我按 ctrl+c 并重新开始时,当他想要运行 sfc /scannow 命令时,它就卡住了。

  @echo off
cls

echo Welkom, Ik ben de ASCI Reparatie Tool.
echo Wat wil je doen?
echo 1. SFC 
echo 2. Bootrec
echo 3. Ping
echo 4. Robocopy
echo 5. 
echo 6.
echo 7.
echo 8.
echo 9.
CHOICE /C 123456789 /N /M "input nummer"

IF ERRORLEVEL 1 SET KEUZE=GOTO SFC
IF ERRORLEVEL 2 SET KEUZE=GOTO bootrec
IF ERRORLEVEL 3 SET KEUZE=3
IF ERRORLEVEL 4 SET KEUZE=4
IF ERRORLEVEL 5 SET KEUZE=5
IF ERRORLEVEL 6 SET KEUZE=6
IF ERRORLEVEL 7 SET KEUZE=7
IF ERRORLEVEL 8 SET KEUZE=8
IF ERRORLEVEL 9 SET KEUZE=9

:SFC 
cls
echo Je wilt dus dde SFC command gebruiken.
echo Welke parameter wil je gebruiken?
echo 1. /scannow 
echo 2. /verifyonly
echo 3. /scanfile
echo 4. /verifyfile
echo 5. /help
CHOICE /C 12345 /N /M "Input nummer"

IF ERRORLEVEL 1 SET KEUZE=GOTO scan
IF ERRORLEVEL 2 SET KEUZE=GOTO only
IF ERRORLEVEL 3 SET KEUZE=GOTO file
IF ERRORLEVEL 4 SET KEUZE=GOTO verify
IF ERRORLEVEL 5 SET KEUZE=GOTO help

:scan

sfc /SCANNOW

pause

exit

:only

sfc /verifyonly

pause

exit

:file

sfc /scanfile

pause

exit

:verify

sfc /verifyfile

pause

exit

:help

sfc /help

pause

exit

这是我的第一个脚本,我不太熟悉如何制作批处理文件

答案1

当使用时CHOICEIF ERRORLEVEL您必须按降序执行错误级别检查,因为IF当值大于或等于检查中指定的数字时,命令将为真IF ERRORLEVEL

 @echo off
 cls

 echo Welkom, Ik ben de ASCI Reparatie Tool.
 echo Wat wil je doen?
 echo 1. SFC 
 echo 2. Bootrec
 echo 3. Ping
 echo 4. Robocopy
 echo 5. 
 echo 6.
 echo 7.
 echo 8.
 echo 9.
 CHOICE /C 123456789 /N /M "input nummer"

 IF ERRORLEVEL 9 SET KEUZE=9 &GOTO :EOF
 IF ERRORLEVEL 8 SET KEUZE=8 &GOTO :EOF
 IF ERRORLEVEL 7 SET KEUZE=7 &GOTO :EOF
 IF ERRORLEVEL 6 SET KEUZE=6 &GOTO :EOF
 IF ERRORLEVEL 5 SET KEUZE=5 &GOTO :EOF
 IF ERRORLEVEL 4 SET KEUZE=4 &GOTO :EOF
 IF ERRORLEVEL 3 SET KEUZE=3 &GOTO :EOF
 IF ERRORLEVEL 2 GOTO bootrec
 IF ERRORLEVEL 1 GOTO SFC
 GOTO :EOF

 :SFC 
 cls
 echo Je wilt dus dde SFC command gebruiken.
 echo Welke parameter wil je gebruiken?
 echo 1. /scannow 
 echo 2. /verifyonly
 echo 3. /scanfile
 echo 4. /verifyfile
 echo 5. /help
 CHOICE /C 12345 /N /M "Input nummer"

 IF ERRORLEVEL 5 GOTO help
 IF ERRORLEVEL 4 GOTO verify
 IF ERRORLEVEL 3 GOTO file
 IF ERRORLEVEL 2 GOTO only
 IF ERRORLEVEL 1 GOTO scan

 :scan
 sfc /SCANNOW
 pause
 exit

 :only
 sfc /verifyonly
 pause
 exit

 :file
 sfc /scanfile
 pause
 exit

 :verify
 sfc /verifyfile
 pause
 exit

相关内容