windows - This batch control statement doesn't work the first time, but does the second time -
here's code:
:login cls if exist "%~dp0\users" ( set /p enteredusername=username: if exist %~dp0\users\%enteredusername%.bat ( phone call %~dp0\users\%enteredusername%.bat ) else ( echo. echo user not exist. echo. pause goto mainmenu ) ) else ( echo no accounts exist. echo. pause goto mainmenu ) set /p enteredpass=password: if %enteredpass%==%password% ( goto begin ) else ( echo. echo wrong password. echo. pause. goto mainmenu )
so programme accesses batch file in user folder. it's called whatever username is.bat. example, if username registered "bob", file bob.bat. if file exists, phone call it, setting username , password variable. issue this: when utilize label first time , prompted come in username, type in "bob". says that doesn't exist (when in fact does). here's curious part, though. next time run , type in "bob", prompts me password , grand. why doing this? give thanks you.
you using %enteredusername% within same if build defined. entire if build loaded (parsed) 1 line. if add together statement like
echo.enteredusername=%enteredusername%
immediately after 'set /p...' line on set see variable empty. enable delayedexpansion, presents problem if username or password has "!" in it. safer solution restructure this. not of code shown here.
login cls if not exist "%~dp0\users" ( echo no accounts exist. echo. pause goto mainmenu ) set /p enteredusername=username: if exist "%~dp0\users\%enteredusername%.bat" ( phone call "%~dp0\users\%enteredusername%.bat" ) else ( echo. echo user not exist. echo. pause goto mainmenu ) set /p enteredpass=password: if "%enteredpass%"=="%password%" ( goto begin ) else ( echo. echo wrong password. echo. pause. goto mainmenu )
windows batch-file if-statement label
No comments:
Post a Comment