What are Batch Files?

I recently was in charge of creating a silent install for an application. While many installations include a silent option, this one was a bit different. I had to also run other installs, as well as import registry settings, and also copy files.

To help me with this task I used a batch file that was easily able to handle everything I needed. If you haven’t used batch files before, then this post will explain what they are and how they can be used.

Batch File Overview

Batch files are nothing more than a text file that executes one or more commands from a command prompt. Unlike other executables that use the “.exe” extension, batch files use the “.bat” extension.

The one reason batch files are used is to execute many commands at one time, like in a batch. This means you don’t have to sit in front of your computer to execute each command separately.

In the early days of the PC, the most common batch file was autoexec.bat, which loaded when you started your computer. This file contained many driver and application settings that were needed to run your computer. This file was at times a source of frustration, especially to get the settings correct.

I still like to use batch files today, as they are quick and easy to create, and can be used to automate such things as a virus scan or defrag at specific times.

Creating a Batch File

As I mentioned, a batch file is easy to create. All you need is a text editor, such as Notepad. When you save a file in your text editor be sure to change the extension from “.txt” to “.bat”.

To execute a batch file, you can just double-click the file in Windows or type its name from a command prompt to execute the batch file.

For example, lets say you wanted to execute a file called “ProgramA.exe” from the “C:\ApplicationA” directory. You would open up your text editor and type:

“C:\ApplicationA\ProgramA.exe”

Once you save your batch file (remember to change the extension to “.bat”), you can then just double-click your batch file and “ProgramA.exe” would run.

If you wanted to also execute “ProgramB.exe” from “C:\ApplicationB”, you would change your batch file like so:

“C:\ApplicationA\ProgramA.exe”

“C:\ApplicationB\ProgramB.exe”

This would execute both “ProgramA.exe” and “ProgramB.exe”.

If you wanted to print out a message to the screen while it ran, you can use the echo command like this:

echo Running ProgramA

“C:\ApplicationA\ProgramA.exe”

echo Running ProgramB

“C:\ApplicationB\ProgramB.exe”

While the above commands are simple, it shows how easy it is to execute more than once command at a time.

I currently use batch files to automate my virus scanner, anti-spyware, and defrag applications, as each of these applications can be executed from the command line. You can read how I do it in the post titled Automating Computer Maintenance.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.