这是我试图制作的第一个批处理文件。它应该是youtube视频的虚假登录服务器。 当我输入错误的密码(在IF语句中)时,我希望它转到ELSE语句,但即使IF语句失败,也会在IF的一侧运行:loop和:loop2。 < / p>
@echo off
title Classified Server Login Service
:prompt
echo Welcome to the Classified Server Login service.
set /p pass="Enter Password: "
IF %pass%==3arc2015 (
echo Logging in...
@timeout /T 3 /nobreak >NUL
cls
echo Login succesful!
set /p title="Enter File Name: "
echo Checking...
@timeout /T 4 /nobreak >NUL
echo File found.
set /p dest="Enter Download Destination: "
echo Destination set!
@timeout /T 1 /nobreak >NUL
echo Beginning download...
@timeout /T 1 /nobreak >NUL
:loop2
cls
echo Contacting Download Server. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server.. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server...(74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server.. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server...(74.56.9.245)
@timeout /T 1 /nobreak >NUL
:loop
set /a num=%num%+1
title Downloading %title%... %num%KB Downloaded.
echo %num%KB downloaded.
goto loop
) else (
echo FAIL
pause
)
set /p a="Press ENTER to close"
答案 0 :(得分:0)
我对IF
和()
不是很好,所以我按照以下步骤进行:
我还添加了3次重试失败。
@echo off
setlocal
title Classified Server Login Service
set /a "_p=0"
:prompt
cls
echo Welcome to the Classified Server Login service.
set /a "_p=_p+1"
IF "%_p%"=="4" goto fail
set /p "_pass=Enter Password: " || set "_pass=NothingChosen"
IF "%_pass%" NEQ "3arc2015" goto prompt
goto logging
:fail
echo fail
endlocal
exit /b 0
:logging
echo Logging in...
@timeout /T 1 /nobreak >NUL
cls
echo Login succesful!
set /p title="Enter File Name: "
echo Checking...
@timeout /T 1 /nobreak >NUL
echo File found.
set /p dest="Enter Download Destination: "
echo Destination set!
@timeout /T 1 /nobreak >NUL
echo Beginning download...
@timeout /T 1 /nobreak >NUL
:loop2
cls
echo Contacting Download Server. (74.56.9.245^)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server.. (74.56.9.245^)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server...(74.56.9.245^)
@timeout /T 1 /nobreak >NUL
:loop
REM title Downloading %title%... %num%KB Downloaded.
FOR /L %%G IN (1,1,10) DO (
cls
echo %%G KB downloaded.
@timeout /T 1 /nobreak >NUL
)
echo download finished.
set /p a="Press ENTER to close"
endlocal
EXIT /B 0
答案 1 :(得分:0)
我知道您可能甚至不记得您的这个项目,但我仍然只是解决您的问题。
发生的事情是cmd无法识别(无论出于何种原因),您结束了IF语句。我所做的是输入“IF NOT”语句。
@echo off
title Classified Server Login Service
:prompt
echo Welcome to the Classified Server Login service.
set /p pass="Enter Password: "
IF %pass%==himan (
echo Logging in...
@timeout /T 3 /nobreak >NUL
cls
echo Login succesful!
set /p title="Enter File Name: "
echo Checking...
@timeout /T 4 /nobreak >NUL
echo File found.
set /p dest="Enter Download Destination: "
echo Destination set!
@timeout /T 1 /nobreak >NUL
echo Beginning download...
@timeout /T 1 /nobreak >NUL
)
IF NOT %pass%==himan CLS & Echo FAILED... Try again & goto prompt
:loop2
cls
echo Contacting Download Server. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server.. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server...(74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server.. (74.56.9.245)
@timeout /T 1 /nobreak >NUL
cls
echo Contacting Download Server...(74.56.9.245)
@timeout /T 1 /nobreak >NUL
:loop
set /a num=%num%+1
title Downloading %title%... %num%KB Downloaded.
echo %num%KB downloaded.
goto loop
set /p a="Press ENTER to close"