Batch files have been around for a long time, actually a Main Frame term from
the early 1960's.
So what is a batch file and what can it do for you?
A batch file is simply a file that is executable with a list of commands to
do a task, a couple of tasks, or even a list of tasks.
The batch file runs from the command prompt or if you are using DOS the
command line.
Some examples of a batch file -
If you start a Command Prompt while in Windows you will use a batch file
called Autoexec.nt - note the .bat is a dos term that stands for batch, like
.com stand for command, .sys stands for system and so on.
If you do a search on your computer you for Autoexec.bat you will not find it
unless you happed to copy it from a DOS environment. On a Windows NT and forward
Operating Systems it is called Autoexec.nt. This is to keep the file from being
executed by mistake. It can only be called (or executed) by the Command Prompt.
Although you can run Autoexec.bat in the Command Prompt it is not a good idea
because the file can set environment variables that could cause your computer to
hang or even crash.
This is what a couple of batch files look like:
Autoexec.bat -
@echo off
CLS
path=a:\
ver
and
Autoexec.nt
@echo off
REM AUTOEXEC.BAT is not used to initialize the MS-DOS environment.
REM AUTOEXEC.NT is used to initialize the MS-DOS environment unless a
REM different startup file is specified in an application's PIF.
REM Install CD ROM extensions
lh %SystemRoot%\system32\mscdexnt.exe
REM Install network redirector (load before dosx.exe)
lh %SystemRoot%\system32\redir
REM Install DPMI support
lh %SystemRoot%\system32\dosx
As you can see there are a lot of abbreviations in the file, each one is
conotated (shortened) because the original DOS
environment was very limited in
memory capacity - it was 640 K maximum in size, most text files now days are
bigger than that!
A short list of explanation for the abbreviations in the sample above:
@echo off - turns off the repeat of the command when it is
executed by the batch file.
REM - Remark - non executable text
lh - load high - load the program in to high memory before
executing the command.
PIF - Program Information File - this file has parameters
and configuration information for the Windows Operating System.
There are a lot more of these abbreviations.
So a batch file will do a lot of things for you once you have studied the
syntax (format) of the command.
You can have a batch file run your backup every day at a certain time.
Or you could have a batch file open different programs at a given time of
day, say you have a meeting every Tuesday at 10:00 AM. for the meeting you will
need Power Point, Excel, Word, and your Netmeeting. Instead trying to remember the
time and to open the programs you could write a batch file then schedule it to
run every Tuesday at 10:00 AM. Then the next Tuesday at 10:00 AM your programs
will open automatically. A boon for us forgetful types.
When your virus scan runs every day at 9;00 AM it is done by a type of batch
file, not the command prompt type but a schedule that has the program name,
location, and time of execution.
So how would you setup the batch file?
Well lets have a look at a file that will open four programs -
Note: Netmeeting has to be setup before it
will work as in this example, you can set it up by typing netmeeting in the run
box from the start button.
Now you have your batch file, note that I named it .cmd, this is the same as
.bat, it is a change that Microsoft introduced with Windows NT because the first
version of the Operating System did not .bat file extension in the code.
So the next step would be to test the file by running it from the command
prompt or the run box with the start button.
How did you do? Messed it up? Well if you copied the lines of commands from
this web page and put it in a word document you copied all the code in the web
page that makes if pretty - the formatting code. Try it again and paste it in to
Notepad.exe then save it with a name and the .cmd extension, put it on your
desktop so you can find it easily.
Now what happened? All four of the programs started?
If your batch file worked your next step would be to schedule the start time
to execute the batch file. You could use the 'AT' command in the batch file but
it is easier to run the Windows Task Scheduler from the Control Panel.
The Task Scheduler is fairly easy to configure the only thing you will have
to remember is where you placed your batch file after you tested it.
There are a lot of things you can use a batch file for running a set of
programs at a given time is just one.
You could use a batch file to open all the programs you use everyday at
startup instead of clicking on them one at a time, just make your batch file
then place it in the startup folder in your profile under the Documents and
Settings folder, or you could schedule it...
In one of my e-courses I setup a way to delay the start of services, using a
batch file you could have your everyday programs open one at a time on a
schedule. The only draw back to using the schedule is that if you are late in
starting your computer the scheduled task time will have passed and the program
will not run, in that case you would have to open it manually.
Here is a sample batch file I made to clean my temp directory:
Rem - This is a batch file to delete all the files from the temporary directory
Rem - Monte Russell 09/03/09
Rem - You are free to modify this file and distribute to all your friends!
Rem - http://www.diy-computer-repair.com
@echo off
Rem select your drive
D:
CD\Temp
del /Q *.*
Rem this file will not delete files inside a folder if you want to add a folder this is how you do it
CD FrontPageTempDir
del /Q *.*
This site contains a lot of information. As
with any publication not all information is available due to space, time, or
subject constraints.
If you have a question that you did not find the answer
on this web site you a can
ask your question here and we will endeavor to get you the most up to date
answer possible!