在CMD中编写密码的问题

时间:2014-02-03 17:57:02

标签: cmd passwords

如果有人键入一个或多个空格的密码,它将退出并返回: 意外(...)

例如:

我输入密码:test 1

它返回:意外1

我的批次刚关闭! 有什么想法让它忽略空格?

这是完整的代码:

@echo off
if time GTR 14.00 goto ALLOW

title Security

echo Your computer started at %date%! Time: %time%! >> Reports.txt

echo taskkill /f /IM explorer.exe
shutdown /s /t 60
msg * Please enter the password in the box!

:START
cls
set /p PSW = Enter the password here: 

if %PSW% == test (
goto END
) else (
if not %PSW% == test goto TRYAGAIN
)

goto start

:END

shutdown /a
msg * Correct!
start explorer.exe
taskkill /f /IM cmd.exe

:TRYAGAIN
msg * Wrong! Try again!
goto START 

:ALLOW
taskkill /f /IM cmd.exe

1 个答案:

答案 0 :(得分:0)

引号保护空格和&字符等。

if "%PSW%" == "test" (
goto END
) else (
goto TRYAGAIN
)