Lab9- Batch file-F22

docx

School

Algonquin College *

*We aren’t endorsed by this school

Course

CST8101

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

7

Uploaded by CaptainField13890

Report
Lab 9 Due date: at the end of your lab period Evaluation 10 Marks. Make sure you answer the questions in part 1 (in red). Make sure your codes are written in the batch file, not any other languages Use Help or Google to search for your batch file ( do not copy, or paste ) Procedure Start the Windows Command Prompt and type in the following commands to see what they do. Part 1: Exercise #1 : Command: CD 1) Type in: CD /? Read the help pages for the cd command. What is the purpose/output of the cd command? Displays the name of or changes the current directory. Exercise #2 : command cd.. Type the following command and press Enter 1) Type in: cd.. /? Read the help pages for the cd.. Command. What is the purpose/output of cd.. Command? It will move the user up one directory. Exercise #3 : command dir Type the following command and press Enter 1) Type in: dir /? Read the help pages for the dir command. What is the purpose/output of dir command? ©Algonquin College Page 1 of 7
Displays a list of the disk are stored files and folders Exercise #4 : whoami Type the following command and press Enter 1) Type in: whoami /? Read the help pages for the whoami command. What is the purpose/output of whoami command? Displays information about the person who is presently signed in to the local system, including user, group, and privilege information. Exercise #5 : cls Type the following command and press Enter Type in: cls /? Read the help pages for the cls command. What is the purpose/output of cls command? Clear the output screen. Exercise #6 : echo Type the following command and press Enter Type in: echo /? Read the help pages for the echo command. What is the purpose/output of the echo command? Switches on or off the command echoing capability or displays messages. Exercise #7 : exit Type the following command and press Enter Type in: exit /? Read the help pages for the echo command. What is the purpose/output of the exit command? It uses to terminate the normal process. ©Algonquin College Page 2 of 7
Exercise #8 : net Type the following command and press Enter 2) Type in: net /? Read the help pages for the net command. What is the purpose/output of the net command? Used to connect to, remove, and configure connections to shared resources, like mapped drives and network printers. Exercise #9 ipconfig Type the following command and press Enter Type in: ipconfig /? Read the help pages for the ipconfig command. What is the purpose/output of the ipconfig command? Displays all of the TCP/IP network configuration values that are currently in effect and updates the DHCP and DNS settings. Type in: ipconfig /flushdns /? Read the help pages for the ipconfig command. What is the purpose/output of the ipconfig /flushdns command? It use clear any IP addresses or other DNS records from your cache. Type in: color /? Read the help pages for the color command. What is the purpose/output of the color command Color is an internal command found in the Windows Command Processor that is used to alter the foreground and background colours of the console. Part 2 : Writing a Simple Batch Program Batch files are used to automate everyday tasks such as helping a computer technician, network administrator, or computer programmer diagnose a network- ing issue or shorten the time it takes to do everyday tasks such as compiling Java programs. Procedure: ©Algonquin College Page 3 of 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The first part is to create a batch file that allows you to test your network adaptor and see if you are connected to a network. Use the ping command to test your network connectivity There are a few simple commands I want to familiarize you with for this program. Commands are NOT c ase sensitive . Ping – it tests your network (computer) connectivity to the internet. TITLE - The Window name for the BAT file. ECHO - the “print” statement for BAT files. Anything following the word ECHO will be displayed in the command prompt as text, on its line. ECHO OFF – BATCH FILE writers typically put this at the beginning of their files. It means that the program won’t show the command that you told it to run while it’s running – it’ll just run the command. I’d recommend that after you run this test program, you try removing this line from your code to see what happens. PAUSE - This outputs the “ press any key to continue… message that you’ve seen all too many times. It’s helpful because it pauses the batch file execution. If you don’t put this in your program, everything will speed by and end before you can see it. Programmers typically put this in batch files to give the user a chance to review the material on the screen before continuing. CLS - Clears the CMD window IPCONFIG – Outputs network information into your CMD box WHOAMI - This utility can be used to get a user name and group information along with the respective security identifiers (SID), claims, privileges, and login identifier (logon ID) for the current user on the local system. ©Algonquin College Page 4 of 7
SET – Sets a variable. If you want to see the content of a variable, use the echo command. With the /p switch you can instruct the set to create a new variable based on the users' input . IF – The IF command ties together batch processing. The IF command responds to the variable created by the set command. GOTO – The GOTO command tells the command prompt to jump to a new loca- tion in the batch file. Chkdsk : Checks a disk and displays a status report. MD - Creates a directory Color - Sets the default console foreground and background colors. Important tip: Make sure you run your batch file as an administrator . Right-click on your batch file and choose Run as Administrator . For some commands, use cmd help on your computer. For instance, for color commands code numbers you type help in cmd, you will see codes for different colors. Opening or accessing any program you need to go to C:\windows\system32 to find the program, for instance, the paintbrush is mspaint.exe . To execute this program make sure to specify the path to this program. C:\windows\system32\ mspaint Example of an IP address: In the command prompt (CMD) type ipconfig and press enter . You will see your IP address for your computer internet connection Create a batch file Open a new text document on your desktop ( notepad) . Double click the file – it should be blank inside. Now, go to file>save as , and in the “ Save As ” window, input a name for your BAT file and then add a .bat on the end. For example, when I created the batch file below I named it lab Lab8 . bat. ©Algonquin College Page 5 of 7
Right-click your BAT file and click “edit” to bring up Notepad and create the batch file. The batch file should have a menu that allows the user with 16 options. The batch file should run until the user chooses to quit the batch file Sample of a menu Option 1: this allows the user to test their network adaptor (NIC card) to see if it is running. Use the ping command Option 2: allows the user to run the ipconfig command. (Shows your IP a d- dress) Option 3: allows the user to release their current IP address for their network adaptor. Option 4: allows the user to renew their network adaptor’s IP address . Option 5: allows the user to remove all entries from their DNS cache i.e. to flush the cache. (DNS) Option 6: this allows the user to stop the print spooler. The command to stop the print spooler is the net stop spooler. Option 7: allows the user to start the print spooler. The command to start the spooler is the net start spooler. Option 8: allows the user to run the whoami command and display their user id and SID. The command is whoami /user. Option 9: Create a directory in C:\ drive with your name. Option 10: Check the hard drive in your computer (scan) ©Algonquin College Page 6 of 7
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Option 11: change letters to green color in the CMD. Option12: change the background to red color for CMD Option13: open the paintbrush program Option14: open the CMD command prompt Option 15 : allows the user to press q to stop the batch file from running. Once you have completed the lab; answer the questions ( in red ) and demon- strate your batch file to your lab instructor. 5 marks Answer the questions 5 marks Run the batch file ©Algonquin College Page 7 of 7