这批/命令脚本有什么问题?

时间:2018-05-27 11:32:21

标签: batch-file

@echo off
echo please enter the correct code in order to continue
set /p %password%=
if %password%==Puzzle (
cls
echo Loading...
ping localhost -n 5 >nul
cls
echo Your next step is "zhekw://vftqi.yczbpw.qzh/jazp/y/"
pause
exit
) else (
echo Loading...
ping localhost -n 5 >nul
echo You have Entered the wrong password, access declined
pause
)

我是批处理的新手,所以我真的不明白这个

有什么问题

2 个答案:

答案 0 :(得分:1)

您将变量设置为:

Set /p "password=enter a password.: "

然后只有设置一次后,你用百分号来调用它:

%password%

还始终将if语句变量括在双引号中,以消除可能的空白。

if "%password%"=="Puzzle"

你可以用超时替换ping,具体取决于你的windows版本。

Timeout /t 5

答案 1 :(得分:0)

LotPings的评论中提供了您的问题的解决方案,语法为Set /P "VariableName=PromptMessage"而非Set /P "%Variable%=PromptMessage"

以下是您的脚本的修改示例:

@Echo Off 
Set /P "password=Please enter the correct code in order to continue: "
ClS
Echo Loading...
Timeout 5 /NoBreak > Nul
ClS
If Not "%password%"=="Puzzle" (
    Echo You have Entered the wrong password, access declined
    GoTo :EndIt
)
Echo Your next step is "zhekw://vftqi.yczbpw.qzh/jazp/y/"
Rem rest of code here


:EndIt
Pause
Exit /B

如果密码输入的区分大小写不重要,请将行7更改为If /I Not…