Sie sind auf Seite 1von 14

Acknowledgment

It is important that you read this before you read the


manual.

While reading this manual, please read everything. Don’t leave


anything out or else you could end up messing up your computer.
I’m telling you this because it happened to a friend once. Make
sure to read it carefully and fully understand it before trying to
create a batch file. If you do not understand one of the concepts of
a batch file or one of the commands, you could contact Microsoft
Support, but in this manual I try to make things as clear as
possible.
Batch programming is very easy to learn, but unfortunately, it is
only for Windows XP, however, a few commands work on Vista.
Only Windows has the appropriate application to run such files;
the command prompt.

NOTICE: Just to let you know, batch files are illegal


to send via e-mail or internet. If you do so you are
breaking the law! I am not in any way responsible for
the batch files you create, therefore; I am not
responsible if you are caught or arrested for illegal
matters. The following manual was created for
educational purposes only.

-1-
Introduction to Batch Files
By Acid Crasher X
Content

 Introduction

 The Command Prompt

 Basic Commands

 Creating a Batch File

 Saving and Executing a Batch File

-2-
Introduction
A batch file is a file by which you can instruct the operating
system to perform a task or action such as: copy, delete, start,
format, etc.
When a batch file is opened, Windows’ Command Prompt opens
up and performs the tasks that are scripted or written in to the
batch file.

Are batch files dangerous?

In some ways, you could say that batch files are dangerous because
they could slow down your computer or they could delete
everything on it, also called formatting.
A batch file is also able to delete Windows’ configuration
components which could alter the way Windows works or it could
make your computer not operate properly.
When creating a batch file, you must be careful with what you
script, because when deleting a file or formatting a disk, there is
no turning back. The file or disk is deleted permanently. In
some occasions, when using the command prompt, it will prompt
or ask you if you are sure that you want to proceed with the action.
In most cases, it doesn’t.

-3-
The Command Prompt
The command prompt is a tool by Microsoft in which you can
instruct the computer to perform a task. Batch files are based on
the command prompt, except that batch files are many commands
at once scripted into a file.
The command prompt looks something like this…

The screenshot shown above has absolutely no commands


displayed.

There are various ways to open the command prompt.


The first way would be the most obvious one:
Start Menu > All Programs > Accessories

There, the application will be listed. An image of this can be


shown on the following page…

This is what the application would look like on the start menu:

-4-
The second way to open it would be to use Windows’ Run
application. You can open run by going to the start menu, there the
application will appear.

Or you could press Windows Key + R. In the Run box, type cmd
which is short for “Command”.

-5-
When opening the command prompt, there are many things you
can do. One of the problems with the direct use of the command
prompt is that you can’t paste text into it. If you try to it would
look something like this.

In this manual I will use the command prompt to show you how
the scripted command would be displayed. I will not show you
how to do things directly from the command prompt because this
is not a manual about the command prompt; it’s a manual about
batch files.

-6-
Basic Commands
To be able to create a batch file, you must first know the
commands you need to use along with the appropriate syntax.
The syntax of a command is everything you write after the
command. For instance, if you want to shutdown your computer,
you cannot just write “Shutdown Computer”, that is not a valid
syntax. The correct syntax would be “shutdown –s”, but we’ll get
into that later on.

To view all of the commands, go to the command prompt and type


help.

-7-
A list of all the commands will appear. Since this is only a basic
Batch File tutorial, I won’t explain all of them but most of them I
will.

CD
This command takes you to another directory. When you first open
the command prompt, you are located in the directory:

C:\WINDOWS\system32

To move to the C:\ drive, you would have to type:

cd\

Then, to get into a specific directory or folder you would have to


type each of the directories in the path. There are actually two ways
to do this. The example of the syntax of the first way would be:

cd Program Files
cd Internet Explorer

The second example of the syntax would be:

cd Program Files\Internet Explorer

It works the same; they both take you to the Internet Explorer
directory.

If you want to go back a directory you type:

cd..

So if you’re in Program Files and type cd.. it takes you to C:\

-8-
CLS
This command clears the screen. Not the Windows screen, the
command prompt screen.
Every command that you have written or scripted will be cleared.
This command is useful for a sequence of tasks on a batch file. For
example: if you want to go to a directory. After going to the
directory, everything you typed is written. You would then type
CLS and then hit enter. Everything will be cleared.

However, CLS is almost never needed when you have a batch file
in “echo off”. I’ll explain that later on.

MD
This command creates a new directory in the directory you are
currently in. If you are in C:\Documents and Settings\ you could
type:

MD New Folder or
MD Any Name

This will create the directory:

C:\Documents and Settings\New Folder

-9-
TITLE
This command lets you change the title of the Command Prompt.
The syntax of this command would be:

TITLE <THE TITLE HERE>

So if you wanted to change the title to “Acid Crasher X”, you


would type:

TITLE Acid Crasher X

It would end up looking like the image below.

COLOR
This command lets you change the color of the Command Prompt.
If you type “color help” in the command prompt, all the color
codes will appear. If I wanted to change the background to black
and the foreground to green, I would type:

COLOR 0a

- 10 -
It would end up looking something like this.

ECHO ON or OFF
ECHO ON makes every command that you type visible. If you type
@ECHO OFF, every command and syntax you type is not going to
be shown, only the result will be displayed. For secret Batch Files I
would recommend you use @ECHO OFF to prevent people from
seeing the commands that are being executed in the Batch File.

ECHO
This command lets you display messages. Not popup messages,
messages printed onto the Command Prompt. The correct syntax
for this would be:
ECHO <message here>
An example would be:
ECHO Acid Crasher X was here...

Also if you type ECHO. (with a dot after “ECHO”) you skip a line
leaving it blank.

- 11 -
COPY

- 12 -
TIME and DATE
These commands are used when you want to set a new time or date
on the computer. By typing only TIME on the command prompt
you can see the current time. By typing only DATE you can see the
current date.
The syntax for TIME would be:

TIME 00:00:00.00
(hh:mm:ss.ml)

The correct syntax for DATE would be:

DATE <mm-dd-yy>

RMDIR
This is a useful command for removing directories. It only works
when the directory is empty. The appropriate syntax would be:

cd\
cd Directory
cd Next Directory
cd Next Directory
RMDIR Directory

If you don’t want to stay in that directory, you can use this other
syntax:

RMDIR “C:\directory\directory\directory”

- 13 -
DEL
This is another very useful command. It is as important as COPY
but this command is a lot more dangerous to mess with.

Warning: When using this command, the deleted file(s) are not sent
to the recycle bin, they are removed from the computer so do not
interfere with system files.

This command deletes any file from your system.

The appropriate syntax for this command would be:

DEL file.extension

But, like any other command you must first go to the directory the
file is in or you must type the path in the syntax. Example:

DEL “C:\Directory\Directory\file.extension”

ERASE

Erase works the same as DEL except that instead of saying…

DEL “file.extension”

…you say:

ERASE “file.extension”

They work the same.

- 14 -

Das könnte Ihnen auch gefallen