Batch File Concept.
The term "batch" file is a misnomer. Essentially, a "batch" file is a text file that contains a number of commands, some of which you can manually type in the CLI. “Batch file” is a misnomer because the term "batch" often implies the lack of user interaction. In reality, a batch file can have basic text-mode user interaction. A more proper term is CLI scripts, or shell scripts.
In the simplest case, you can use notepad and just enter a sequence of CLI commands as if you would in a CLI. The only requirement, however, is that the file must have an extension of bat (for batch). In fact, you can do the following right now:
- click “Start” button
- select “run...”
- type “notepad”, click OK
- in the editor, type the following
dir c:\
dir "c:\Program Files"
pause
- in the file menu, select save
- name the file "test.bat", make sure you select "all files" for "Save as type"!
- save the file to a folder where you can find it. The default “My Documents” is fine.
- use Windows Explorer to navigate to where you saved the batch file.
- double click the batch file
- press ENTER when the CLI says "Press any key to continue"
- close the CLI if it does not terminate automatically
Although this batch file does not do anything useful, it is a good illustration of how easy it is to write a "program" using CLI commands.
Systems Maintenance Tasks
As discussed in a previous chapter, your computer benefits from periodic maintenance efforts. Some of these tasks can be automated with batch files.
Check disk
chkdsk is the command to check the integrity of a partition. However, if you want to fix detected problem with the /f(slash F) option, this command requires a reboot to take effect. Consequently, it is not a good idea to include chkdsk in a maintenance batch file.
Defragmentation
On the other hand, the command defrag can be included in a maintenance batch file. This is because the command defrag does not require any reboot. If there are multiple partitions, a batch file can defragment the partitions one by one.
No comments:
Post a Comment