0

I have created a batch file menu (named "menu.bat") which lists three sub-menus linked to their respective batch files, as follows:

  1. Network Functions (networkfunctions.bat)
  2. Control Panel (controlpanel.bat)
  3. Accessories (accessories.bat)

The batch filename of each selection (i.e., 1, 2, 3) is in parentheses.

I have all these .bat files saved on my computer in the following directory structure:

c:\batch


Here is the script found in menu.bat:

echo off
title Main Menu
::menu.bat
::Contains main batch file menu
cls
:menu
echo.
echo                           ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo                           º MY NAME HERE ÄÄ Main Menu º
echo                           ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo                           º 1. Network Functions       º
echo                           º 2. Control Panel           º
echo                           º 3. Accessories             º
echo                           º 4. Exit                    º
echo                           ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo.
set /p input="Select number: "
if %input% ==4 goto Exit
if %input% ==3 goto Accessories
if %input% ==2 goto Control Panel
if %input% ==1 goto Network Functions

:Network Functions
start c:\batch\networkfunctions.bat
pause
goto menu

:Contol Panel
start c:\batch\controlpanel.bat
pause
goto menu

:Accessories
start c:\batch\accessories.bat
pause
goto menu

:Exit
exit

Here is the script in network.bat:

echo off
title Network Functions
::networkfunctions.bat
::contains network functions and utilities for use on the
::command prompt
cls
:menu
echo.                                                  
echo                    ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo                    º  MY NAME HERE Ä Network Functions  º
echo                    ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo                    º  1. IPCONFIG                        º
echo                    º  2. IPCONFIG /ALL                   º
echo                    º  3. NETSTAT                         º
echo                    º  4. NSLOOKUP                        º
echo                    º  5. Telnet                          º
echo                    ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĹ
echo                    º  6. Return to Main Menu             º
echo                    º  7. Exit                            º
echo                    ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo.
set /p input="Select number: "
if %input% ==7 goto Exit
if %input% ==6 goto Return to Main Menu
if %input% ==5 goto Telnet
if %input% ==4 goto NSLOOKUP
if %input% ==3 goto NETSTAT
if %input% ==2 goto IPCONFIG /ALL
if %input% ==1 goto IPCONFIG

:IPCONFIG
start c:\windows\system32\ipconfig.exe
pause
goto menu

:IPCONFIG /ALL
start c:\windows\system32\ipconfig.exe \all
pause
goto menu

:NETSTAT
start c:\windows\system32\netstat.exe
pause
goto menu

:NSLOOKUP
start c:\windows\system32\nslookup.exe
pause
goto menu

:Telnet
start c:\windows\system32\telnet.exe
pause
goto menu

:Return to Main Menu
start c:\batch\menu.bat
pause
goto menu

:Exit
exit

Here is the script in controlpanel.bat:

echo off
title Control Panel
::controlpanel.bat
::contains a menu of pertinent control panel applets
cls
:menu
echo.                                                  
echo                    ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo                    º    MY NAME HERE Ä Control Panel    º
echo                    ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo                    º  1. Configuration Manager           º
echo                    º  2. Internet Options                º
echo                    º  3. Network Connections             º
echo                    º  4. System Properties               º
echo                    º  5. Windows Firewall                º
echo                    ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĹ
echo                    º  6. Return to Main Menu             º
echo                    º  7. Exit                            º
echo                    ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo.
set /p input="Select number: "
if %input% ==7 goto Exit
if %input% ==6 goto Return to Main Menu
if %input% ==5 goto Windows Firewall
if %input% ==4 goto System Properties
if %input% ==3 goto Network Connections
if %input% ==2 goto Internet Options
if %input% ==1 goto Configuration Manager

:Configuration Manager
start rundll32.exe shell32.dll,Control_RunDLL C:\WINDOWS\system32\CCM\SMSCFGRC.cpl
pause
goto menu

:Internet Options
start rundll32.exe shell32.dll,Control_RunDLL c:\windows\system32\inetcpl.cpl
pause
goto menu

:Network Connections
start rundll32.exe shell32.dll,Control_RunDLL c:\windows\system32\ncpa.cpl
pause
goto menu

:System Properties
start rundll32.exe shell32.dll,Control_RunDLL c:\windows\system32\sysdm.cpl
pause
goto menu

:Windows Firewall
start rundll32.exe shell32.dll,Control_RunDLL c:\windows\system32\firewall.cpl
pause
goto menu

:Return to Main Menu
start c:\batch\menu.bat
pause
goto menu

:Exit
exit

Here is the script in accessories.bat:

echo off
title Accessories
::accessories.bat
::contains a menu of pertinent utilities and applications
cls
:menu
echo.                                                  
echo                    ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo                    º     MY NAME HERE Ä Accessories     º
echo                    ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo                    º  1. DOS Edit                        º
echo                    º  2. Notepad                         º
echo                    º  3. System Information              º
echo                    º  4. System Restore                  º
echo                    ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĹ
echo                    º  5. Return to Main Menu             º
echo                    º  6. Exit                            º
echo                    ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
echo.
set /p input="Select number: "
if %input% ==6 goto Exit
if %input% ==5 goto Return to Main Menu
if %input% ==4 goto System Restore
if %input% ==3 goto System Information
if %input% ==2 goto Notepad
if %input% ==1 goto DOS Edit

:DOS Edit
start c:\windows\system32\edit.com
pause
goto menu

:Notepad
start c:\windows\system32\notepad.exe
pause
goto menu

:System Information
start c:\program files\common files\microsoft shared\msinfo.exe
pause
goto menu

:System Restore
start c:\windows\System32\restore\rstrui.exe
pause
goto menu

:Return to Main Menu
start c:\batch\menu.bat
pause
goto menu

:Exit
exit

THE PROBLEM


I can execute menu.bat successfully. I am presented with the three selections.

  1. Network Functions
  2. Control Panel
  3. Accessories

If I select "1," I am taken to "Network Functions" sub-menu. Perfect.

If I select "3," I am taken to "Accessories" sub-menu. Perfect.

If I select "4," I exit the Windows Command Line. Perfect.

The problem is if I select "2"; it provides the following error:

The system cannot find the batch label specified - control

The drive label then changes from c:\ to c:\batch.

The curious thing is that I CAN execute the file c:\batch\controlpanel.bat if I enter it in the Run box. It works perfectly.

But, if I try to execute it through the menu.bat file, it does not execute.

What's going on here? Any help is appreciated. I'm this close to finishing this class project.

Thank you in advance.

2 Answers 2

2

You misspelled Control Panel as Contol_Panel.

4
  • Good eye. Seems like the obvious solution, but after fixing that underscore, the problem persists. I actually neglected to remove that _ before posting this thread because I was trying to figure out if filename "controlpanel.bat" was the problem. So, I decided to throw an underscore in there. It didn't work. Anyway, like I said, nothing changed. Problem is still there.
    – user76275
    May 1, 2011 at 18:50
  • 2
    @user: ... there's no R...
    – Hello71
    May 1, 2011 at 18:56
  • Sorry, I don't quite understand that response.
    – user76275
    May 1, 2011 at 19:06
  • I see it now! Wow, good eye.
    – user76275
    May 1, 2011 at 19:13
1

@Hello71 is correct. Look below that directly illustrates what needs changing. It doesn't have anything to do with an underscore.

   echo off
    title Main Menu
    ::menu.bat
    ::Contains main batch file menu
    cls
    :menu
    echo.
    echo                           ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
    echo                           º MY NAME HERE ÄÄ Main Menu º
    echo                           ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
    echo                           º 1. Network Functions       º
    echo                           º 2. Control Panel           º
    echo                           º 3. Accessories             º
    echo                           º 4. Exit                    º
    echo                           ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
    echo.
    echo.
    set /p input="Select number: "
    if %input% ==4 goto Exit
    if %input% ==3 goto Accessories
    if %input% ==2 goto Control Panel 
    if %input% ==1 goto Network Functions

    :Network Functions
    start c:\batch\networkfunctions.bat
    pause
    goto menu

    :Contol Panel <<- It's spelled "Control" not "Contol"

    start c:\batch\controlpanel.bat
    pause
    goto menu

    :Accessories
    start c:\batch\accessories.bat
    pause
    goto menu

    :Exit
    exit

Some other recommendations:

  • When testing a variable for a specific value, you should enclose both parameters in quotes, like this:

    if '%input%'=='4' goto Exit

Since the batch command processor substitutes variables with their contents before interpreting the command, this avoids syntax errors if %input% happened to be null or undefined for some reason. Just a good habit to develop.

You also didn't account for the fact that the user might enter something besides 1, 2, 3, or 4. So, the result in your script is that it will "fall through" to the Network Functions section which could be confusing. You should echo an error message and goto back to the input statement if %input% doesn't match anything expected. Another good habit.

2
  • Excellent! Amazing how I missed that. Good catch Hello, and thank you for elaborating ultrasawblade. I will do more research on the error messages and incorporate both of your recommendations in my script. Thank you again for taking the time to answer.
    – user76275
    May 1, 2011 at 19:14
  • You beat me to that! :( Mar 5, 2018 at 17:04

You must log in to answer this question.