Solved CMD if / else complication

May 9, 2012 at 17:55:09
Specs: Windows XP
@echo off
echo Please enter the password!
SET /P B =
If B EQU 5 (
) Else (
Echo Incorrect
goto A

it basically is saying:
please enter the password

and then if it is correct, it runs the batch file OP1, but if it is incorrect it says "Incorrect", and restarts the program.

I wrote this password script, but when i try to run it, it always says the password is incorrect no matter what. Does anyone have a solution?

See More: CMD if / else complication

Report •

May 10, 2012 at 06:32:54
✔ Best Answer
@echo off
set B=
set /A count=4
rem changed to this prompting style by preference, feel free to change back
echo you have %count% attempts left
SET /P B="Please enter the password:: "

rem this changed statment asks if the variable is equal to 5
rem next line starts your batch, and ends this program
if %count% equ 1 goto ends1
If %B% EQU 5 start OP1.bat && goto ends

rem no need for a else command, because the
rem only reason to continue and not prompt for a
rem password, is success
set /a count=(count-1)
Echo ****Incorrect password****
goto A
echo You have Tried Too Many Times. Press Enter to Continue



Report •
Related Solutions

Ask Question