Log in

View Full Version : Batch program - password protect and open program



alexjewell
09-11-2007, 10:26 AM
I wrote a batch program to open a program depending on a right or wrong password:



cls
@echo off
set passWord = samplepassword
goto CHECK

:CHECK
echo SUP HOMIE:
set/p "pass=>"
if %pass%==%passWord% goto OPEN
goto END

:OPEN
echo Right Password...
@START "C:\Program Files\SampleProgram\SampleProgram.exe"
goto END

:END
echo closing...
pause


It doesn't work, though. No matter what you type in as the password, it goes to END. Before, when I was messing with it, I got it to OPEN, but it went to OPEN no matter what the user inputted. And, what opened was not the program, just a command prompt with the address of the program in the title.

Any ideas?

tech_support
09-12-2007, 06:29 AM
set passWord = samplepassword
No spaces in between the equal sign. It means that the batch script will look for %passWord % and not %password%

set/p "pass=>" should be set /p pass="Password=> "

And lastly, there's no need for start. You can use cmd /c [COMMAND]

Here's the working code:



cls
@echo off
set passWord=samplepassword
goto CHECK

:CHECK
echo SUP HOMIE:
set /p pass="Password=> "
if %pass%==%passWord% goto OPEN
goto END

:OPEN
echo Right Password...
cmd /c "C:\Program Files\SampleProgram\SampleProgram.exe"
goto END

:END
echo closing...
pause