GUIDE TO (mostly) HARMLESS HACKING
Microsoft-only version Number 3
Hacking with Win95/NT: Batch File
We've learned what
a batch file is and how to write them. Now it's
time to get all that batch files can bring us. Lets start.
1.- The IF command
It's easy to find
out what it is for. The if command evaluates an
a condition and, in case of true result, it executes a command.
three ways to use IF. The different sintax are these:
IF [NOT] EXIST file
IF [NOT] string1==string2
IF [NOT] ERRORLEVEL
Where command is the
order (only one) you want to execute. The
NOT word is optional, and it makes the condition inverese. Lets
**IF [NOT] EXIST
What it does is to
find out if there is or not a file. If the file
exist (or not, if the NOT word is typed) then the command is
Otherwise, the command is ignored.
TIP: Maybe you don't want to verify a file, but a drive or a
this case, you have
to look for the "file" NULL, that is present in
any directory. For
example, if you want to verify the c:\nezah
directory, type this:
IF EXIST C:\NEZAH\NULL command
To test if a disquette
is in, type this:
IF EXIST A:\NULL command
**IF [NOT] string1==string2
Compares the two strings
string1 and string2. In case that every
character is equal in both (case sensitive and blank spaces ignored),
command is executed.
It is useful to play
with the parameters (read GTmHH Micro$oft 2).
Note now that, when a parameter call is found (for example, %1),
it for the text of the parameter, no matter where it is. For
example, if %1
is Happy, when DOS finds:
replaces it for:
The same with
"%1" ---> "Happy"
" %1 " ---> " Happy
NOTE: If a parameter does not exist, DOS replaces it with a blank
just with nothing
(in W95 OSR2 is nothing). To avoid lose control of
the program, is useful
to put every string into quotes. So, for example,
if you want to see
if a parameter is present, type:
IF "%1"==" " command --->
IF "%1"=="" command
---> In W95 is empty string ""
In any other cases,
quotes are not needed and strings are compared
**IF [NOT] ERRORLEVEL
This evaluates the
last errorlevel number present. Errorlevels are
generated by programs to inform about the way they finished their
For example, format returns errorlevel 3 when is Ctrl-C is pressed,
errorlevel 0 when it finish normally. Not all the programs return
and errorlevels are lost when another program is runned.
This is the most useful
feature of IF command. We'll explain it later,
with the CHOICE command.
2.- Labels and
Labels are used to
identify a line of the batch file. The way to
put a label inside a .bat progam is simply to put : before the
For example, to create the "example" label, do this:
And that's all.
Labels get useful
when you use the order GOTO. GOTO simply goes to
the labeled line you want. For example, to go to the :example
label just type:
That makes the execution
of the .bat file continue above that line,
no matter if it was far below the current line or before it.
NOTE: The label does not defines a function (like in programming
It makes the execution
continue below the :label line.
When, in normal execution,
a :label line is found, it is ignored. The
only use of lables
is with the order GOTO.
TIP: You can create a :end label at the end of the file, so that,
you want to finish
the program, you just have to type "GOTO :end".
TIP: Remember that, in the IF sentence, only was allowed one
This sucks, I know.
But now, you can create a label and make this
only one command be
GOTO :label. Then, in this :label you can have
as many commands as
you want, and finish the execution or return to
the program point
you wanted with :end or :new_label
More batch programming--->>