1.

Solve : Batch menu that works on every windows version??

Answer»

Since the CHOICE command is not available on WINDOWS 2000 and XP, I used a construction like this:

Code: [SELECT]:start
ECHO.
ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid please TRY again
ECHO.
goto start
Thing is that this batch isn't just for me and needs to WORK on a variety of windows versions. So my QUESTION is this: Will this work on Vista/Win7?
See no reason why it won't. Best way to find out is to test it. The code will not work on Win9x machines.

To make it completely idiot proof, you could test what version of Windows is running (use the ver command in a for loop) and design your file to use either choice or set /p.

  Quote from: Kolya on April 22, 2010, 06:30:24 AM


Thing is that this batch isn't just for me and needs to work on a variety of windows versions. So my question is this: Will this work on Vista/Win7?


Test on Win7:

C:\>type  menu.bat
echo off
:start
ECHO.
ECHO 1. print Hello
ECHO 2. print  Bye
ECHO 3. print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid please try again
ECHO.
goto start

:hello
echo Hello
goto start
:test
echo test
goto start
:bye
echo bye

C:\>menu.bat

1. print Hello
2. print  Bye
3. print Test
Type the number to print text.1
Hello

1. print Hello
2. print  Bye
3. print Test
Type the number to print text.3
test

1. print Hello
2. print  Bye
3. print Test
Type the number to print text.
"" is not valid please try again


1. print Hello
2. print  Bye
3. print Test
Type the number to print text.2
byeI don't have access to Windows 7, so I couldn't test it. I also thought about running two ways with an OS check and using "choice" or "set /p".
But I got confirmation meanwhile that it works on Windows 7.
Thanks for your help.


Discussion

No Comment Found