批处理脚本不会更正标签

时间:2013-08-04 20:44:25

标签: batch-file

我正在处理批处理脚本以解锁某些帐户(如果存在)并根据结果转到标签。

当前的脚本有效。它最终没有找到正确的标签。我知道标签必须按照正确的顺序排列,但我只是不明白这个顺序是什么以及如何正确检查错误级别。

@echo off

cls
echo -------------------
echo Unlocking Account0...
echo -------------------
pause
net user Account0 /active:yes
goto %ERRORLEVEL%

:0
cls
echo -------------------
echo Account0 unlocked successfully!
echo Press any key to reboot now. 
echo -------------------
pause
goto reboot


:2
cls
echo -------------------
echo Account0 not found. Unlocking Account1...
echo -------------------
pause
net user Account1 /active:yes
if errorlevel 2 goto 3
if errorlevel 0 goto 0


:3
cls
echo -------------------
echo Account0 and Account1 not found!
echo Please make sure that one of these accounts exist.
echo You can use the command "net user <accounthere> /active:yes" to manually unlock an account.
echo -------------------
pause
goto END

:END
cls
echo NONE FOUND, EXIT SCRIPT.

:reboot
cls
echo ACCOUNT FOUND, REBOOT HERE 

就是这样。没有什么花哨。它只是没有找到正确的标签。

2 个答案:

答案 0 :(得分:0)

见IF /?

if errorlevel 2 goto 3

如果errorlevel大于或等于2,则转到3 你可能想要:

if %errorlevel% equ 2 goto 3
if %errorlevel% equ 0 goto 0

答案 1 :(得分:0)

而不是使用

goto END

使用内置的

goto :EOF

默认情况下会转到文件的末尾(注意冒号)。