Presentation is loading. Please wait.

Presentation is loading. Please wait.

Additional information

Similar presentations


Presentation on theme: "Additional information"— Presentation transcript:

1 Additional information
Batch script file Additional information

2 Important DOS Concepts Batch script file
Objectives… What is a Batch File? Stopping a Runaway Batch File Creating a Batch File Editing a Batch File Passing Parameters to a Batch File Commonly used Batch File Commands Controlling other applications in Batch File Chapter 5 adds (37 slides) CTEC 110

3 Important DOS Commands Batch script file
copy con source of copy is the console rem comment pause program stops until a key is hit echo displays back information to the console call passes control to another batch file choice offers user options for execution goto transfers control to different part of batch file if checks conditions of two or more variables shutdown powers down Windows taskmgr Brings up Task Manager Chapter 5 adds (37 slides) CTEC 110

4 Objectives Create useful batch files
Define the role of batch files in the DOS environment Identify different batch file commands and their use Create batch files using the DOS COPY command List those steps required to create a file from the CONSOLE (keyboard) Understanding how those commands work Control the execution of those commands What else can we do with batch files? Be able to reference the DOS Command Index: Chapter 5 adds (37 slides) CTEC 110

5 What is a Batch File? Executable program Sequence of commands
Time saver Often used for automation at startup Chapter 5 adds (37 slides) CTEC 110

6 Simple Example Chapter 5 adds (37 slides) CTEC 110

7 Other Examples Can be long and tedious!! Take a look at GO.BAT
On the root of the N Drive Chapter 5 adds (37 slides) CTEC 110

8 Chapter 5 adds (37 slides) CTEC 110

9 Chapter 5 adds (37 slides) CTEC 110

10 Chapter 5 adds (37 slides) CTEC 110

11 Stopping a Runaway Batch File
Ctrl + C Stops a batch file “Terminate batch job (Y/N)?” Answer this question with a “Y” (Yes)… Chapter 5 adds (37 slides) CTEC 110

12 Creating a Batch File COPY CON example.bat
CON stands for console (the keyboard) whereby the commands entered into keyboard will automatically be put into the file example.bat Ctrl + Z places an end-of-file character in the file and stores it on disk. Can also use notepad in Windows Chapter 5 adds (37 slides) CTEC 110

13 Creating a Simple Batch File
Make the root of the O drive your default Type in the following commands: COPY CON o:\look.bat dir tree Ctrl + Z <enter> TYPE look.bat look.bat Chapter 5 adds (37 slides) CTEC 110

14 Editing a Batch File notepad look.bat FileOpen
Dropdown boxchoose “All Files” Select look.bat Add these commands at the end date /t time /t Close and save look.bat Chapter 5 adds (37 slides) CTEC 110

15 Editing a Batch File REM used for comments notepad look.bat look.bat
Comments are not acted upon notepad look.bat Add at the beginning of the file: REM This file was created by <Your Name> REM On <Today’s Date> Close and save look.bat Chapter 5 adds (37 slides) CTEC 110

16 Editing a Batch File ECHO displays information back to the user
ECHO string of words ECHO by itself displays a blank line Usually displays the ECHO setting (ON or OFF) Try using a period (.) instead (put a space before) PAUSE is for stopping the program until the user hits a key Chapter 5 adds (37 slides) CTEC 110

17 Editing a Batch File Go back to editing the look.bat file
Change all the REMs to ECHOs Add PAUSE on the line between the last ECHO and before DIR Run the batch program again LOOK.BAT Chapter 5 adds (37 slides) CTEC 110

18 Editing a Batch File Go back to editing the look.bat file
Add a PAUSE between DIR and Tree Run the batch program again LOOK.BAT Chapter 5 adds (37 slides) CTEC 110

19 Looking at a Real Batch File
Check out the WUGXP folder on the G drive for the batch file called GO.BAT type WUGXP\go.bat Chapter 5 adds (37 slides) CTEC 110

20 Passing Parameters BatchFileName 1stPar 2ndPar 3rdPar …
Parameters in file: %1 %2 % Create NAME.BAT on the root of O Drive COPY CON name.bat ECHO Your first name is %1 ECHO Your last name is %2 Ctrl + Z name.bat David Sims Chapter 5 adds (37 slides) CTEC 110

21 Passing Parameters Create NAME.BAT on the root of O Drive
COPY CON times.bat %1 /t %2 /t Ctrl + Z times.bat date time Chapter 5 adds (37 slides) CTEC 110

22 The ECHO command The ECHO command syntax: Examples: ECHO [ON | OFF]
ECHO [message] Displays messages, or turns command-echoing on or off. Type ECHO without parameters to display the current echo setting Examples: ECHO ECHO is on. ECHO This is a message! This is a message Chapter 5 adds (37 slides) CTEC 110

23 The ECHO command ECHO OFF - turns off the display of commands
COPY CON rems.bat REM This is a comment line ECHO OFF REM This comment line will not be seen CTRL + Z rems.bat Chapter 5 adds (37 slides) CTEC 110

24 The ECHO command Use notepad to adjust times.bat Save and close
ECHO OFF Add %1 /t %2 /t Save and close times.bat date time Chapter 5 adds (37 slides) CTEC 110

25 The CALL command The CALL command syntax: Example:
CALL [d:][path]batchfilename [options] Calls another batch file, then returns to current batch file to continue Example: CALL go.bat Chapter 5 adds (37 slides) CTEC 110

26 The CALL command Use notepad to adjust times.bat times.bat date time
ECHO OFF %1 /t PAUSE Add CALL o:\look.bat Add %2 /t Save and close times.bat date time Chapter 5 adds (37 slides) CTEC 110

27 The CHOICE command The CHOICE command syntax: EXAMPLES:
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text] This tool allows users to select one item from a list of choices and returns the index of the selected choice ERRORLEVEL variable set to choice 1,2,3, etc ERRORLEVEL is 0 on CTRL + C ERRORLEVEL is 255 when invalid choice is made EXAMPLES: CHOICE /? CHOICE /C YNC /M "Press Y for Yes, N for No or C for Cancel." CHOICE /T 10 /C ync /CS /D y CHOICE /C ab /M "Select a for option 1 and b for option 2." CHOICE /C ab /N /M "Select a for option 1 and b for option 2." Chapter 5 adds (37 slides) CTEC 110

28 The CHOICE command (Second look)
The CHOICE command syntax (second look…): CHOICE [/C:[:]list of keys] [/N] [/S] [/T[:]choice,number] [text] CHOICE is used to make batch files interactive The /C switch followed by set of keys and a question mark Default are Y and N keys The /S switch keys must match the case of letters The /T switch is the number of seconds a user has to press keys Examples: CHOICE /C:ABCDN /N /T:N,10 Format drive A:, B:, C:, D: or None? IF ERRORLEVEL 1 SET DRIVE=drive A: IF ERRORLEVEL 2 SET DRIVE=drive B: IF ERRORLEVEL 3 SET DRIVE=drive C: IF ERRORLEVEL 4 SET DRIVE=drive D: IF ERRORLEVEL 5 SET DRIVE=None ECHO You chose to format %DRIVE% Format drive A:, B:, C:, D: or None? Chapter 5 adds (37 slides) CTEC 110

29 The GOTO command The GOTO command syntax: Example: GOTO (label)
Transfer control to a labeled line The LabeledLine needs to have a “:” as the first character and no spaces Example: echo off :START LabeledLine echo This is an infinite loop goto START Chapter 5 adds (37 slides) CTEC 110

30 The GOTO command Create a batch file called infinite.bat
ECHO OFF :START ECHO This is an infinite loop GOTO START Save and Close infinite.bat Infinite.bat (execute the batch file) Chapter 5 adds (37 slides) CTEC 110

31 The IF command COPY CON SecretWord.bat SecretWord.bat linux ECHO off
IF not linux==%1 GOTO MESSAGE ECHO you guessed the right word GOTO END :MESSAGE ECHO you made a bad guess :END SecretWord.bat linux Chapter 5 adds (37 slides) CTEC 110

32 Calling Other Programs
Shutdown (Has a variety of options) Display a Graphical User Interface Logoff Shutdown Computer Shutdown and Restart Computer Force Running Applications to close Taskmgr (Starts up the Windows Task Manager) Will start up the Task Manager Good for troubleshooting Windows Chapter 5 adds (37 slides) CTEC 110

33 shutdown -l Chapter 5 adds (37 slides) CTEC 110

34 Calling Other Programs
Try to run some of the following commands on your own… Some of these may take some time to complete It is best to understand what they do before attempting to execute them!!! Chapter 5 adds (37 slides) CTEC 110

35 cleanmgr.exe Disk Cleanup compmgmt.msc Computer Management
calc Calculator cleanmgr.exe Disk Cleanup compmgmt.msc Computer Management desk.cpl opens the display properties devmgmt.msc Device Manager diskmgmt.msc Disk Management eventvwr Windows Event Log (Event Viewer) explorer . Open explorer with the current folder selected. firewall.cpl Opens the Windows Firewall settings lusrmgr.msc Local Users and Groups Administrator mmsys.cpl Sound/Recording/Playback properties mstsc.exe Remote Desktop Connection perfmon Opens Reliability and Performance Monitor powercfg.cpl Power management control panel applet regedit Registry Editor Chapter 5 adds (37 slides) CTEC 110

36 runas Run specific tools and programs with different permissions than the user's current logon provides schtasks Enables an administrator to create, delete, query, change, run and end scheduled tasks on a local or remote system. secpol.msc Local Security Settings services.msc Services control panel systeminfo Displays a comprehensive information about the system tasklist.exe List Processes on local or a remote machine whoami /all Display Current User/Group/Privilege Information winver.exe Find Windows Version wscui.cpl Windows Security Center Chapter 5 adds (37 slides) CTEC 110

37 END of Additional Information
HOMEWORK Lab 4 DOS Quiz 4 Chapter 5 adds (37 slides) CTEC 110


Download ppt "Additional information"

Similar presentations


Ads by Google