Hi
I was learning about batch file programming and making this
paper so that i could remember the commands but this paper
solely taken the form of tutorial.Well it isnt completed yet but i
will provide soon the complete text.
So here it goes
++++++++++++++++++++++++++++++
Well batch file is the easiest way to implement and run set of
DOS commands by just running a single file.Batch files can be
easily made and edited using any of the text editor (I preffer
using notepad because i use it :-)
Simply if you want to read the code of the batch file open it in
notepad or select edit option by right clicking on it. and if you
want to create one batch file write code in notepad and SAVE AS
file as xxx.bat. The main thing is to make it .bat extension.
Codes which can be used in batch files.
According my current knowledge every command which can be
use in DOS can be used in a batch file.
1. dir
===
if you want to run dir command then the code for batch
file will be as follows:
After writing this in notepad save it whatever.bat and
when you run it,a dos window will appear and you can see the
directory structure of that directory where whatever.bat is
placed. Now if you want to look at the other dirctory say windows
then code will be
Code:
cd c:\windows\
dir /p
Here "cd c:\windows\" will switch us to windows folder
and "dir /p" will show the files and folders.( /p at the end of dir
stands for showing files and folders page wise)
Now there is another facility through which instead of
displaying output it can save the output to a file.This is done as :-
This will create a text file named as "info" at C: drive
which contain the detail files and folders of the directory where
the batch file is executed.
2. echo
====
This will show whatever you write after it.
EXAMPLE
OUTPUT
Code:
C:\WINDOWS\Desktop>echo hi
hi
the first line shows where the batch file is placed
followed by command executed.
You can create the fake error message just for fun.
EXAMPLE
Code:
echo This program uses to much resourses.Please shut
down windows now.
OUTPUT
Code:
C:\WINDOWS\Desktop>echo This program uses to
much resourses.Please shut down windows now.
This program uses to much resourses.Please shut
down windows now.
but any one can easily understand that it is a fake
message by reading first line.
3. @
=
Well one can hide first line i.e path and command
executed simply by adding "@" before any command.It just dont
shows the path and the command executed.It can be applied
approximately on every command.
EXAMPLE
Code:
@ echo Welecome to Dos
OUTPUT
If echo command is followed by off keyword (i.e "echo
off") then nothing will be displayed and the dos window will
appere only for a sec or less than a sec.
Well this command will be very useful its importance is
discussed later in this article.
4. md and rd
=========
This is stand for make directory and remove
directory.The syntax is simple "md name" AND "rd
name".Here "name" is the name of the folder which you want to
create.
NOTE:-For removing a directory or we can say for deleting the
folder it is nessecary that the folder should be empty.I dont think
that example for these command is needed
5. pause
=====
Here another intresting command.this will ask the user
to press any key to continue.
EXAMPLE
Code:
@ echo FATAL ERROR
@ pause
OUTPUT
Code:
FATAL ERROR
Press any key to continue . . .
Now this actually looks like a error message:-)
6. start
=====
This command is used when we want to open files from
the batch file.
EXAMPLE
this will open up the "abc" named jpg file within that
folder.we can also open .exe .bmp etc...; even we can open other
batch file from this command.For the file located in other folder
we have to just add the path of it followed by file name.OK one
thing is to be noted that whatever file you open from this
command will open in a new window.
Now some evil fun.you can create infinite loop of start
for make your screen messy.just you have to do it that make two
batch files within a folder.for example xyz.bat and abc.bat. Now in
xyz.bat write code:-
and in abc.bat write code:-
This will open up endlessly dos windows.well i warn
you for for getting out this infinte loop you have to very quickly
click on the close button and then to yes button before the next
window opens.
7. call
====
It is similar like the start command but it can only be
used to open other batch files.
Start command opens the file on other dos window While this
command will open other batch files within the same window.So
the call command is the extension of start command which is
limited on batch files only.
EXAMPLE
(abc.bat)
Code:
@ Eminem is cool
@ call xyz
(xyz.bat)
OUTPUT
Code:
Eminem is cool
Press any key to continue . . .
This is all happens in a single dos window.If the file is
placed on other folder then blah blah blah.... you know what to
do.
NOTE:- This command is only limited to batch files thats why it is
not nessecary to specify extension i.e *.bat.Our command will
work without it too.
8. goto
====
Goto command is used like a unconditional repeate
loop or a jump instruction.There are to part in this command that
are goto itself and label.now we understand them one by one
1st LABEL:- this act like a pointer to goto
instruction.This can be any keyword specified by you.before it we
have to add a colon " : ".
2nd goto:- This will call the specifed label.
I know this will not clear you to till now.example will clear your
view.
EXAMPLE
goto as a jump command
Code:
@ echo This text will displayed
@ goto itsalabel
@ echo This text will not be displayed
: itsalabel
Here Last line is label.the colon should be followed by
any keyword.In our example "itsalabel" is our keyword.
OUTPUT
Code:
This text will displayed
C:\WINDOWS\Desktop\New Folder>
after outputting the first line the goto instruction will
send excecution to its label that is fourth line due to which third line will be skipped.
ANOTHER EXAMPLE
goto as unconditional repeat loop
Code:
@ echo hello
@ pause
: itsalabel
@ echo hi
@ goto itsalabel
It will print hello one time and then will print infintly "hi".
ANOTHER ANOTHER EXAMPLE
Code:
@ echo This text will displayed
@ pause
@ goto label1
: label2
@ exit
@ echo This text will not be displayed
: label1
@ goto label2
This example can be easily understood if you have
readed this text thourghly.
9. For
===
This is the conditional loop.Dont have much information
on it:-(
10. del
===
For deleting files.
EXAMPLE
This will delete all text files of that folder.As you can
see that it would ask for a confirmation.
If you are using win98 then and want to crack the password of a
windows login account write code
Code:
@ del c:\windows\*.pwl
NOW SOME EVIL STUFF(Do Not Try This At Home)
Code:
@ echo off
@ echo y | del c:\window\*.*
Second line code will make it to not to ask for
confirmation.This will damage your system.but the system and
hidden files will not be deleted.
Windows XP's del command give you facilite to delete files on
basis of there attributes( /A Selects files to delete based on
attributes.attributes: R Read-only files,S System files,H Hidden
files,A Files ready for archiving,- Prefix meaning not)
11. Deltree
=====
Delete files and directory too.
Code:
@ echo off
@ deltree c:\newfolder\*
special about this command is that this deletes
dirctories and sub directories including files.It is a command to
delete files and folders.
Another Speciality is that it also delete the hidden and system
files which the del command was unable to do.
Another Another specialty is that windows does provide to skip
confirmation.here how to do it.
MORE EVIL STUFF(Do Not Try This At Home)
Code:
@ echo off
@ detree /y c:\window\*
the '/y' stands for yes to all.
NOTE:-
I would prefer not to become Evil.Think how to use your skills to
create some thing not to destroy.Well I would not be responsible
for any kind of damage occured in your system by my tutorial.By
the way I have taken precaution.I have written "windows"
as "window" in code so that it would not damage any moron
system who just do's the copy-paste ........ and run it without
reading note like this.
INCOMPLETE
+++++++++++++++++
Well my intension is not to create harmful files and codes but to
get aware you how it (batch file viruses) works.As i have
mentioned before that i was not making tutorial so please donot
post drawbacks.The posts which tells more about batch file
programming is MOST WELCOME.and also apprietiation posts
Does i have posted in right place?
KNOWLEDGE IS POWER
BUT ONLY IN RIGHT HANDS