Hack Forums

Full Version: Basic Batch Tutorial
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The basics of batches.
Author : Unclean Spirit.

@echo off
title Batch file
echo Testing 1 2.. Testing 1 2 3
pause
@echo on
echo Testing 1 2.. Testing 1 2 3
pause>nul
@echo off
color 0f
cls
echo Testing 1 2.. Testing 1 2 3
pause>nul
cls
msg * Testing 1 2.. Testing 1 2 3
cls
pause
cls
echo Do you like pie?(1 for yes and 2 for no)
set /p question=
if '%question%'=='1' goto :yes
if '%question%'=='2' goto :no
exit

:yes
cls
echo Cool me too.
pause
exit

:no
cls
echo Damn it,I do.
pause
exit


Ok,copy the whole code,and paste it into Notepad.Then click File>Save as change File type to All Files and save it as something.bat
Then run it.
You will get something like this:

A window with the title Batch file
then the following
Testing 1 2.. Testing 1 2 3
Press any key to continue...
When you press a key:
Directory > echo Testing 1 2.. ...
Testing 1 2....
And here a Blank Line
When you click a key
Everything disappeares
Color changed
Testing 1 2...
Then a blank line
When you click a key
Everything disappears and a pop-up comes and says:
Testing 1 2...
Then Press any key to continue
When you press a key
Everything disappears
And you get the following
Do you like pie (1 for yes and 2 for no)
And then you have the ability to type
If you type 1 then you will get this
Cool me too.
Press Any Key to continue
When you press a key,the window closes
And if you press 2
Damn I do.
Press Any Key to continue
When you press a key,the window closes

Let's break it down to the explanation.

@echo off hides the directory.
And @echo on shows it.
Simple.

Echo is just like Print in other languages.
It gives you the ability to type.
Let's say you want to type Test.
Then you don't put in Notepad
Test.
But
Echo Test.

The pause stops the batch untill you press a key.
And types Press Any Key to continue...
On the other hand,pause>nul doesn't show Press any key to continue..
But it has the same ability as Pause

Color just let's you set the colors.
The first color is for the background and the second for the font.
You can get a Color Code list by going into CMD and typing Color Help.

cls = Clear Screen.

Now the set.It basically just makes a variable called question.
Notice the set /p QUESTION=.
And gives you the ability to type.

IF tells the batch file to do something IF %Question% which was set before is equal to something.
So in this case,if a user types 1 it will GOTO :yes.

: sets a title,or a point.Where you can go to it.

Exit.. well.. Exits.

Well these are the basics thanks.
ty ty Biggrin
Thanks,you're the best!Thumbsup
Reference URL's