0

I have written the following code

choice /m "Do you want to add another profile" if errorlevel 1 set /p profile_name1=Enter one of the above profile names: 

However it always runs "Enter one of the above profile names:" even though I pressed no. What did i do wrong?

Thanks!

2
  • Did you mean: %errorlevel% ?, also please edit your post to include the code formatting so we can read it better Commented Oct 25, 2009 at 1:56
  • Jonno, i tried to the first time it just does what it does above!!!! This looks better I am sorry : choice /m "Do you want to add another profile" if errorlevel 1 set /p profile_name1=Enter one of the above profile names: And NO i dont mean %errorlevel% Commented Oct 25, 2009 at 3:28

2 Answers 2

2

You need to give instructions for each outcome. E.g.:

choice /m "Do you want to add another profile" if errorlevel 2 goto :doOtherStuff if errorlevel 1 set /p profile_name1=Enter one of the above profile names: :doOtherStuff 

Also note that the order is important, you must list the errorlevels in descending order (2 then 1).

Sign up to request clarification or add additional context in comments.

Comments

0

First, /m is not a valid argument you can pass to choice. Try removing that, it might be confusing choice.

Also: IF ERRORLEVEL returns TRUE if the return code was equal to or higher than the specified errorlevel. Try checking every possible return value (in your case, both yes and no)

IF ERRORLEVEL 2 SET ANS="No" IF ERRORLEVEL 1 SET ANS="Yes" 

and use the value of ANSwer in the rest of your batch file.

4 Comments

Wrong, according to the result of choice /?: /M text Specifies the message to be displayed before the prompt. If not specified, the utility displays only a prompt.
I think you are wrong. The only documented switches I can find are /C, /N/ S/ & /T - do you have a reference? I'd like to know.
I have a basic windows XP install - I don't even have choice on my machine, so I only have online documentation to go by as far as that goes, but the real problem is the errorlevel line anyways.
@Jan: in newer versions of Windows, the choice command has different switches, including /M. For Win 7 for example, you get: CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.