Writing Batch Programs

First of all, what is a batch program?
A batch program, also known as a batch file executed a list of commands when run.

#What commands?
Run-->type (cmd)-->help

All these commands can be added to a batch file to be executed.
They are very very useful ;)

#Creating batch files.

Just create a file with the .bat extension
I would recommend creating it using cmd as it would allow you to get a hold of the environment.
Open a cmd window. (Run-->type (cmd)
At the prompt, type: ECHO pause >> c:\mybatch.bat
This will create a batch file in your c:\ directory.
Don't bother about the ECHO and stuff, you will understand in due time.

Now run the created file.
You will get a cmd window asking you to press any key, this is because of the pause command that we directed to the file.

To edit the file, right click and edit. A notepad will open with the first line as "pause"

#Writing your batch file.

Delete the pause line.
Type the following:
ECHO OFF               (this insures that actual commands are not displayed when the file is run)
CLS                    (this clears the screen after the ECHO OFF command has been displayed)
TITLE=Shell            (this set the window title as "shell")
ECHO My name is Farell (this outputs "My name is Farell" in the window)
PAUSE                  (this prevents the program from existing right after executing the commands)

You should get a window like the one below..


#Other things you can do

ECHO OFF
CLS
SET /p myname=Enter you name:
ECHO==============================
ECHO.
ECHO %myname% is fan of hax0rs-sh3ll
ECHO.
ECHO==============================
PAUSE

You should get a window like the one below:


Explanation:
The [set /p myname=]   Asks user for input (/p) and store it in the variable "myname"
[ECHO.]                Displays a blank line on the screen
ECHO [%myname%]        Displays the contents of the variable "myname"

You can set a lot of things using set /p.. The rest is up to your imagination. Type help in cmd :)
#Cool Stuffs

Saving system environment to file.
This batch file will save system info like machine name, user profile path and username to a file named sysinfo.txt
System environment variables can be viewed by typing "set" at a cmd prompt.
As they are variables already defined in cmd, we just need to call them.

ECHO OFF
CLS
SET FILE=c:\sysinfo.txt
ECHO %logonserver% >>%file%
ECHO %userprofile% >>%file%
ECHO %username%    >>%file%
ECHO ((Info Saved))
PAUSE

Explanation:
The >> operator saves the output of the command to the variable %file%

Ending note::
There are a lot of things you can do with batch file, search the net for more tutorial and info.
I will be posting a batch file that copies file contents to a USB disk. Stay rooted :)