Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to make a quick little installer and uninstaller app, because I seem to use these little resources a LOT, and it's set up to have y mean uninstall, and n mean end the script, standard stuff, the problem is if I type a non y or n key, it automatically uninstalls.

How can I make it fail on non y/n keys?

Also, can I make it display the entered key on a new line, so it's more visible?

Here's my script.

SET /P ANSWER=Do you want to uninstall? (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :uninstall)
if /i {%ANSWER%}=={n} (goto :end)
goto :end

~EDIT~ Changed the script to look like this, same behavior.

if /i %ANSWER% == y goto :uninstall else goto :end
share|improve this question
    
Please move the 'I figured it out' part from the question to an answer, then mark it as the correct answer –  Jan Doggen May 3 '13 at 9:01
    
Any reason you can't use something like choice with ErrorLevel instead? It's made specifically for this sort of usage. –  Karan May 4 '13 at 1:41

2 Answers 2

You could do if equals y and then an else or not equal to y.

share|improve this answer
up vote 0 down vote accepted
SET /P DELETE=Do you want to uninstall (Y/N)?
echo You chose: %DELETE%
if !DELETE! == y (goto uninstall) else (goto cancel)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.