Need help creating a bat file!?

Hi I am in a scripting class and I just do not get it. I could use any guidance. First I will post the assignment then What I have so far


You are to develop a command script that displays a list of options to the user, prompts for input, and
runs the function selected. The menu interface should have the following characteristics:
¿ At command file startup, the color should be set to white text on a blue background and the
screen should be cleared
¿ The menu options should be centered on the screen
¿ A title for your utility should be displayed at the top of the menu
¿ The date and time should be displayed at the top of the menu directly after or under the title
¿ The screen should be cleared before displaying the menu after commands are run
The menu should include the following options:
1. List drivers installed on PC
2. Get file security info (prompt user for file name)
3. List current running tasks
4. Kill task (prompt user for task name)
5. Display a text file on the screen (prompt user for file to display)
6. List installed printers
7. Show Hostname
8. Show IP addresses
9. Show DNS servers
10. Show Default gateway
Other considerations:
¿ Your script should include appropriate comments documenting your code
¿ You may rearrange the menu options in any way that you wish
¿ You should display a prompt for the user to input an option
¿ Output that runs more than the length of the command window should be paged with the user
prompted to press a key to view the next screen.
¿ The user should be given time to examine the output of their selection before the menu is

What I have so far

@echo off
REM Color Change
color 1f
REM clear screen
REM menu choices
TITLE network menu
echo please choose an option
ECHO 0) list drivers installed on PC
ECHO 1) get file security info
echo 2) list current running tasks
ECHO 3) kill task
ECHO 4) display a text file on the screen
ECHO 5) list installed printers
ECHO 6) show hostname
ECHO 7) SHOW IP addresses
ECHO 8) Show DNS servers
ECHO 9) show default gateway
choice /c:0123456789
IF ERRORLEVEL 9 ipconfig
IF ERRORLEVEL 8 nslookup
IF ERRORLEVEL 7 ipconfig /all
IF ERRORLEVEL 6 hostname
IF ERRORLEVEL 5 net view zach-pc | find /i "print">printers.txt
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

ZoppoConnect With a Mentor Commented:
Hi meade470,

well, I guess you know we're not allowed to do your homework, but we can give you hints what's wrong with your code and we're allowed to point you to the right direction when you're stuck.

So here are some hints about some generic things:

- to clear the screen you can use CLS command
- the index you use with CHOICE is wrong, if the CHOICE isn't cancelled the ERRORLEVEL is set to the 1-based index, so your IFs should check for values 1-10 instead of 0-9
- to let the user input some data (for functions 2, 4 and 5) you can use SET /P (check it's help)
- to break the output of commands to pages you can use MORE (check it's help)
- if I understand it correctly the script should not terminate after a command was executed, so you need to jump to the echo please choose an option instruction after the command was executed. This can be done using GOTO (check it's help)
- your dummy statements like IF ERRORLEVEL 4 produce syntax errors so you can't test anything below this line. To avoid this you can simply add i.e. a REM like this:
- the command you use to display printers doesn't show the installed printers, instead it shows the printers shared from the hardcoded PC "zach-pc". I.e. here I found a way to retrieve the list of installed printers using WMIC, maybe you can use this:
- IMO you should filter the output in some cases (i.e. to display only DNS-Servers from output of IPCONFIG)

Beside these I think you need to find the missing commands to retieve info about drivers, tasks, drivers ...

I hope this helps,

meade470Author Commented:
Haha yeah I figured it was worth a shot..  Thanks for the help though this did help a lot!
Great, I'm glad I could help ...

Have a nice day,

best regards,

Hi meade470.  I realise that this question is closed, and that it was answered as well as is possible within the constraints of the "homework" rule by Zoppo, but I thought that I might just add a couple of pointers should you ever need to create another batch file.

The CHOICE program in Windows 95, 98, ME, 2000 with Support Tools or Resource Kit  installed, was removed in XP, then reintroduced with changes in 2003, Vista, and 7 (  Some people obtained the choice.exe from Win2000 and put it in their C:\Windows\System32 folder in XP rather than having to change all their batch files to use the alternative SET option (

SET /P INPUT=Prompt String To Display.

This prompts for input and sets the input string to a variable named in the command.  In the above example the variable name is INPUT. The value stored in the variable can then be echoed, tested, etc. using %INPUT%.  The variable will contain the same values until overwritten by some other string from another SET command.  Using SET /P you don't have to test the %ErrorLevel% return which can be confusing (

You can use the IF command to test using different methods (

if "%INPUT%"=="SomeValue"
if not "%INPUT%"=="SomeValue"

if %INPUT% EQU SomeValue
if %INPUT% NEQ SomeValue

and can add the /I switch so that it ignores the case of the value when using alphabetic characters.

When running another command from a batch file you can do this in a couple of different ways:

You can CALL it so that control is passed to it and it then returns control back to the same place in the batch file that called it once the other process finishes.  You can CALL an external EXE, BAT, CMD, or other executable program file, you can CALL a recognised internal "DOS" command, and you can CALL a :LABEL within the same batch file. (

As Zoppo states, the GOTO LABELNAME is most commonly used for this type of thing (  The  echo immediately followed by a dot/period/full-stop just echoes a blank line to the screen and can be handy for spacing things out.  

echo A. Some Menu Option Here
echo B. Another Menu Option Here
echo The other menu options listed here
echo H. Help
echo Q. Quit
SET /P INPUT=Type your choice here:

REM All the IF tests here

REM etc, etc, etc

MORE < helpfile.txt

Note that you do not need a label named  :EOF.  It just means "end of file" and simply goes there and exits.  You can instead have an  :END  label, and use that as your "Quit" label, and have a few cleanup commands there before it closes the batch file if required.  

The easiest way to test a menu and your :Labels is to use ECHO instead of the program command and pause processing like this:

REM cls
echo This is the DNSCHECK Label
goto MENU

REM cls
echo This is the LISTTASKS Label
goto MENU

Start with a framework like that, and then add your program commands and remove the pauses once you know that your menu is jumping to the correct labels and then returning to the menu again.

I hope this helps.
All Courses

From novice to tech pro — start learning today.