menu system in dos batch file

Soldato
Joined
17 Jan 2006
Posts
2,890
Location
Dundee
I am writng a small batch file that i can use to display my ip details,along with a ping test and release/renew options.

I have got the goto and cmd options working, just need to sort out the menu system.

This is what i'm using

"
@Echo off
REM IP Utility batch file
REM Graeme Lawrence
REM 16/7/08
REM Version 1.0

:menu

ECHO Please select a function
ECHO -----------------------
ECHO 1. Get Ip Settings
ECHO 2. Ping BBC Website
ECHO 3. Release IP
ECHO 4. Renew IP
ECHO 5. Quit
PAUSE

CHOICE /C:12345 /N Choose 1, 2, 3, 4 or 5
IF ERRORLEVEL 1 GOTO ipconfig
IF ERRORLEVEL 2 GOTO ping
IF ERRORLEVEL 3 GOTO release
IF ERRORLEVEL 4 GOTO renew
IF ERRORLEVEL 5 GOTO quit
"

Also on the quit option how do I get the command window to kill itself?

Can anyone out there give me some advice.

Cheers
 
Right got the menu system working, now it wont go back to the menu

Here's the new code:

:menu

ECHO Please select a function
ECHO ------------------------
ECHO 1. Get IP Settings
ECHO 2. Ping BBC Website
ECHO 3. Release IP
ECHO 4. Renew IP
ECHO 5. Quit Program

set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto ipconfig
if '%choice%'=='2' goto ping
if '%choice%'=='3' goto release
if '%choice%'=='4' goto renew
if '%choice%'=='5' goto end
ECHO "%choice%" is not valid please try again
ECHO.

goto menu

:ipconfig
cls
cmd /k ipconfig.exe
pause
cls
GOTO menu

Can anyone see something I cant?
 
get it to call itself?

as in CALL filename.bat

?

EDIT : does not work. The problem seems to be that when the "cmd /k ipconfig.exe" is called things seem to change to the cmd processor and away from the batch file. If I type in 'EXIT' it runs again to the menu.
 
Last edited:
That's what this does :\.

although replacing '.\filename.bat' with 'goto menu' works fine.


the GO mebnu command does not seem to work. It's def something to do with the fact the a command lime is opened to the ipconfig.exe file. It's like it's "Right let forget the batch file now we're at a command prompt!"
 
I should have seen this earlier.
change the line
cmd /k
to
cmd /c

/k carrries out the command and stays where it is
/c carries out the command and returns.

/c is the default when you run a program without the cmd bit which is why
Code:
:ipconfig
cls
ipconfig.exe
pause
cls
goto menu
works.

Simon
 
Last edited:
^yep, no idea why it isn't working for Swordfish
the GO mebnu command does not seem to work. It's def something to do with the fact the a command lime is opened to the ipconfig.exe file. It's like it's "Right let forget the batch file now we're at a command prompt!"
well it works fine here :confused:.
 
Have a look at AutoIt, I find in much more powerful then batch and not much more complicated.

Will have a look at that, but the main idea behind this was that I install SOHO routers for people and sometimes get calls asking me why "the internet has stopped working". If I leave this batch file on each machine I do I can get IP info from my customers a lot easier than asking them to get it manually.

In my experience when it comes to routers the problem is usually that the machine has lost its ip and reverts to the private style (169.xxx.xxx.xxx) and this would help me establish if this was the problem before driving back out to them.

I am going to try and get this written in VB next (keeps me from getting bored!!!)
 
Back
Top Bottom