Creating a

Your supervisor has been reviewing case histories for all trouble calls received during the last six months. She leaves a message stating that 35% of the problems that you have been working on are related to a lack of basic system maintenance. Your task is to create a batch file to perform basic system maintenance task such as DEFRAG, CHKDSK, and SCANDISK.

Steps:

1.____ Change to the C:\DOS subdirectory.

 We’ll use the DOS editor to create a batch file with the name TEST.BAT. Remember you must use .BAT as the extension.

2. ____ Type: EDIT TEST.BAT

3.____ Type: @ OFF on the first line.

 In our second line, we’ll clear the screen of any messages or items that were displayed before the batch program was executed.

4. ____ Type:

 Throughout the file we’ll be inserting explanatory text using REM. This documents what the batch file does.

5.___ Type the lines below into your batch file. REM This is a batch file that uses a menu. REM The menu will have several options. REM This allows the display of the options.

 You can use the ECHO command to display a menu with a .

6.____ Enter the lines below into your file. ECHO. ECHO. ECHO. ECHO. System Maintenance Menu ECHO. ECHO..1…De-fragment your Hard Disk ECHO..2…Check your Hard Disk ECHO..3…Scan your Hard Disk ECHO..4… to DOS ECHO.

7._____ Press and to Exit.

8. _____ Answer “Y” when prompted to save the file.

 Now let’s try out our batch file.

Instructor Verification ______

9.____ the prompt, : TEST

 Answer the questions on your answer sheet.

10.____ Verify that the menu displays correctly with no errors.

 We’ll now make our batch file a little complex. Once again, use the DOS editor.

11.____ Type: EDIT TEST.BAT  Lets make the menu interactive so that it will accept typed input. To do this, we’ll use the CHOICE command.

12.____ At the end of the file type: CHOICE /C:1234 Please select a number

NOTE: /C:12345 specifies valid number that the user can type. The rest of the command adds text, prompting the user what to do next.

13.____ Add a REM statement above the CHOICE command explaining how it works. Now we must tell the batch file what to do based on input to the CHOICE command. With CHOICE the first key assigned after the “/C:” takes on a value in DOS, or an ERRORLEVEL, of “1.” The second key takes on the value, or ERRORLEVEL, of “2.” Following this logic for the rest of the numbers in the CHOICE command, there are 4 ERRORLEVELS, valued 1 – 4. We can now use IF statements with the ERRORLEVELS. If a particular number is typed, and therefore an ERRORLEVEL is recorded for DOS, the batch file will jump, or GOTO, a different area of the file and execute any commands found there. Let’s try it out.

14.____ Add the following to the end of your batch file. IF ERRORLEVEL 4 GOTO EXIT IF ERRORLEVEL 3 GOTO SCANDISK IF ERRORLEVEL 2 GOTO CHKDSK IF ERRORLEVEL 1 GOTO DEFRAG

15.____ Add a REM above each IF statement explaining its function.

The words after GOTO in each line are called labels. The batch file will look for the that corresponds with the ERRORLEVEL recorded by the CHOICE COMMAND. The label must be preceded by a colon (:). Type each label section in the order that it appears in the IF statements. Be sure to use the exact syntax.

16.____ Add these lines to the bottom of your batch file.

:EXIT GOTO END

:DEFRAG \DOS DEFRAG C: /F GOTO END

:CHKDSK CD \DOS CHKDSK /F GOTO END

:SCANDISK CD \DOS SCANDISK/ALL/AUTOFIX/NOSUMMARY GOTO END

:END

17.____ Press to drop down the File Menu.

18.____ Type “X” to choose exit and then “Y” when prompted to save.

19.____ Execute the batch file by typing: TEST

20.____ Test option 1, De-fragment your Hard Disk. Test option 2; Check your Hard Disk. Continue executing the batch file options 3 and 4. Correct any errors.

Submit your completed Batch File to Canvas