我试图创建一个检查是否
的批处理文件C:\Pswrd.Zask
,C:\Pswrd.Zask\Username.Zask
,C:\Pswrd.Zask\Password.Zask
都存在。
如果目录中的两个文件存在,批处理应该在PasswordScreen
上继续。
但批量处理应继续CreatePasswordScreen
,如果它们不存在的话。
create CreatePasswordScreen
块要求输入用户。然后将该输入存储到名为Password.Zask
&的文件中。文件夹Username.Zask
内的C:\Pswrd.Zask
。
在程序的第二次运行时,程序检查该文件夹的存在,用户名文件和密码文件,然后设置用户名&密码从C:\Pswrd.Zask
到PasswordScreen
块之前的变量,用于确定密码是否正确。
问题在于我无法将密码和用户名作为变量正确存储在批处理文件中,而批处理过程最终因未知原因而终止。
我错过了使用命令吗?
问题应该在:UsernameExist
之后的那一行。
@echo off
color 0a
if not exist "C:\Pswrd.Zask\" (
mkdir "C:\Pswrd.Zask\"
if "!errorlevel!" EQU "0" (
goto DirectoryExist
) else (
echo Created the folder "C:\Pswrd.Zask"
)
) else (
goto DirectoryExist
)
:DirectoryExist
if exist C:\Pswrd.Zask\Password.Zask (
goto PasswordExist
) else (
goto CreatePasswordScreen
)
:PasswordExist
if exist C:\Pswrd.Zask\Username.Zask (
goto UsernameExist
) else (
goto CreatePasswordScreen
)
:UsernameExist
for /f "Delims=" %%A in (C:\Pswrd.Zask\Password.Zask) do (
set CHECKPASSWORD=%%A
for /f "Delims=" %%B in (C:\Pswrd.Zask\Username.Zask) do (
set CHECKUSERNAME=%%B
goto PasswordScreen
:CreatePasswordScreen
cls
echo Create a password.
echo.
set /p "CREATEPASSWORD= Enter password : "
set /p "CREATEUSERNAME= Enter username : "
echo %CREATEPASSWORD% >> C:\Pswrd.Zask\Password.Zask
attrib C:\Pswrd.Zask\Password.Zask -s -h & echo Password Created!
echo %CREATEUSERNAME% >> C:\Pswrd.Zask\Username.Zask
attrib C:\Pswrd.Zask\Username.Zask -s -h & echo Username Created!
echo.
echo Loading...
timeout /5
:PasswordScreen
color 0a
cls
echo Existing User Account.
echo.
set /p "PASSWORD= Enter Password : "
set /p "USERNAME= Enter Username : "
if %PASSWORD%==%CHECKPASSWORD% goto Operation1True
if not %PASSWORD%==%CHECKPASSWORD% goto OperationFalse
:Operation1True
if %PASSWORD%==%CHECKPASSWORD% goto Operation2True
if not %PASSWORD%==%CHECKPASSWORD% goto OperationFalse
:OperationFalse
color 0c
echo Password Incorrect!
timeout /10
goto PasswordScreen
:Operation2True
cls
echo Password Correct!
pause
我找到了解决方案,我偶然发现了以下内容。
@echo off
color 0a
if not exist "C:\Pswrd.Zask\" (
mkdir "C:\Pswrd.Zask\"
if "!errorlevel!" EQU "0" (
goto DirectoryExist
) else (
echo Created the folder "C:\Pswrd.Zask" & timeout /t 5
)
) else (
goto DirectoryExist
)
:DirectoryExist
if exist C:\Pswrd.Zask\Password.Zask (
goto PasswordExist
) else (
goto CreatePasswordScreen
)
:PasswordExist
if exist C:\Pswrd.Zask\Username.Zask (
goto UsernameExist
) else (
goto CreatePasswordScreen
)
:UsernameExist
for /f "Delims=" %%A in (C:\Pswrd.Zask\Password.Zask) do (
set CHECKPASSWORD=%%A
)
for /f "Delims=" %%B in (C:\Pswrd.Zask\Username.Zask) do (
set CHECKUSERNAME=%%B
)
goto PasswordScreen
:CreatePasswordScreen
cls
echo Create a password.
echo.
set /p "CREATEPASSWORD= Enter password : "
set /p "CREATEUSERNAME= Enter username : "
echo %CREATEPASSWORD% >> C:\Pswrd.Zask\Password.Zask
attrib C:\Pswrd.Zask\Password.Zask +s +h & echo Password Created!
echo %CREATEUSERNAME% >> C:\Pswrd.Zask\Username.Zask
attrib C:\Pswrd.Zask\Username.Zask +s +h & echo Username Created!
start %~n0%~x0
exit
:PasswordScreen
color 0a
cls
echo Existing User Account.
echo.
set /p "PASSWORD= Enter Password : "
set /p "USERNAME= Enter Username : "
if %PASSWORD%==%CHECKPASSWORD% (
goto Operation1True
) else (
goto OperationFalse
)
:Operation1True
if %USERNAME%==%CHECKUSERNAME% (
goto Operation2True
) else (
goto OperationFalse
)
:OperationFalse
color 0c
echo Password Incorrect!
timeout /t 10
goto PasswordScreen
:Operation2True
cls
echo Password Correct!
echo.
pause