Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Batch Programing 101


Batch Programing 101

By ghostghost | 7339 Reads |
0     0

basic batch tut. By god of fire. if you want this tut in batch form e-mail me at tehh4cker@gmail.com

first off you should know that this will mainly work on windows 2000 and up. if you have 98 not all of the commands will work. if you have 98 either upgrade or stop reading. also batch is an all text programing languge. you can still make some cool games on it like rouge. if you don't know what rouge is go to www.freearcade.com and choose their text adv. section.

1:Makeing a batch file

to do some basic practicing you should go to run and type in cmd or command once your done haveing fun you should then make a batch file.

to make a batch file you need to first right click and select a new text document. after that you can rename the text document whateveryouwant.bat.

Name it .bat is very important if you don't it will stay a text file. if you have the computer set so this won't change the document then you have to open the text file and SAVE AS something.bat with the save as type being ALL FILES. then you have a batch program.

To edit this program you will need to right click it and click EDIT. this will bring up a text file where you right the code.

2:Basic commands. the first command you need to know for batch is the pause command if you don't have it then the program will go through everything faster then you can blink and close it self automatically. you should almost always have a pause command before the end of the program.

some fun commands are the color command and the echo command. the color command changes all the font and the background to whatever color you choose.

the echo command shows text.

for example

echo hello world pause exit

would show something like this

c:\documents\user>echo hello world hello world. push any key to continue.

now it shows you what you have typed and then it shows the command if this is in a batch file it would look like crap. so you add in the @echo off command.

@echo off echo hello world pause exit

would look something like this

Hello world push any key to continue.

as you can see the @echo off command makes it so it doesn't show what you have typed as the command or the part of the computer it is in.

color works like this

at the begaining of a file you would type @echo off and then the color. you have lots of choice for the color

0 Black 8 Gray 1 Blue 9 Light Blue 2 Green A Light Green 3 Aqua B Light Aqua 4 Red C Light Red 5 Purple D Light Purple 6 Yellow E Like Yellow 7 White F Bright White

these are your choices of color. to now you use color command you would type COLOR then the background color then the font color. like COLOR 0c would give you light red text and a black background

3:loops the eaist loop is like this

:a echo hello goto a

if that was a program it show hello over and over and over again. if you want you could use this with color like so.

@echo off echo hello :a color fc color 1e color 2f color 75 goto a

this would show the word hello while forever changing colors.

  1. Varibles. to make a varible you need the set command. the set command is really hard to explain plus i don't think i even know enough of it to tell you how it works. you want to find out about the set command in cmd type SET /?

you would type

set varible_name=either an equation or a line of text. forever more if you want to use that varible you would type it with precentage signs surrounding it.

3+%varible_name%

that would add 3 and the varible that you have made. if you want to combine to varibles you need set /a. it would work like this. say the first varible is v1 and the secound is v2

set v1=3 set v2=2 set /a bob %v1%+%v2%

this would show the number 5 as it is adding v1 and v2.

if you want to have the user of your program type in a varible you need set /p

set /p v1=Text that displays on the screen.

so if you want you user to type a number you would have

set /p number=Type in your first number:

then from then on %number% would be whatever they typed.

5:Math programs.

the only math symbols that work are

      • and / thats plus minus multitplycation and division. so you could make a program that would do all your addition work. it would probly use the set /p and /a commands and would probly look like this.

set /p input= input your first number: set /p input2= input your secound number: set /a billy=%input% + %input2% echo %billy% is the answer! pause exit

you could use this with Subtraction Mult, Division as well.

6: Dividing your program into sections.

you already know you can devide parts of programs with :A :b :c but what if you have more? and it's not a loop? then you need to make a menu!

if you have a menu that takes to 3 differnt parts of the program, one show text saying moo, one showing letters saying 003 and one showing l337 saying /\/\00

for this you would need the set /p so the user can type in a letter/number/word to go to the site.

@echo off color 0c echo if you want to go to the area saying moo type 1 echo if you want to go to the area saying 003 type 2 echo if you want to go to the area sayihng /\/\00 type 3 set /p menu=where do you want to go?: if %menu%==1 goto moo if %menu%==2 goto 003 if %menu%==3 goto /\/\00 … . that would be using the if command. which is simply like saying. if this happens do this. the == signs mean if %menu% equals exactly 1 the goto some other part of the program so it gives you three choices of where to go. then you type in your choice and it will take you there.

this is usefull for the calculater program. if you want to do addition or subtraction you can choose.

7:The calculater program This program uses a few other commands then the ones i have so far tought you.

cls clears the page title adds a name at the top part of the program.

thats about it. heres the program

Title Calculater Program Made by God Of Fire. @ECHO OFF CLS :menu echo what do you want to do? echo. echo + echo - echo * echo / set input=nothing set /p input=choice: if %input%==+ goto a if %input%==* goto m if %input%==/ goto d if %input%==- goto s goto menu :a set /p input= input your first number set /p input2= input your secound number set /a billy=%input% + %input2% echo %billy% is the answer! pause cls goto menu

:s set /p input3= input your first number set /p input4= input your secound number set /a billy2=%input3% - %input4% echo %billy2% is the answer! pause cls goto menu

:m set /p input5= input your first number set /p input6= input your secound number set /a billy3=%input5% * %input6% echo %billy3% is the answer! pause cls goto menu

:d set /p input7= input your first number set /p input8= input your secound number set /a billy4=%input7% / %input8% echo %billy4% is the answer! pause cls goto menu

8:A few other random commands start this will start up a website or program.

start www.hellboundhackers.org will make hellboundhackers open on a new webpage. start c:some_program_name will open the program. start will just open a new command window.

msg * some message will make a pop up show whatever you want it to say

it's very fun with the loop command.

well thats all. i know it's not much but i thought it was enough to teach you how do to some real basic programing. not just some tut that shows you how do one thing with out leaving anyroom to be creative. with this knowlege you have gain you could make a txt adv. a annoy pop up program. and more.

Also i would like to thank http://batch-hack.leachim.info/ for teaching me all this they have some tut's on batch that makes this one look reeeeal sad. also they have 2 fun batch games you should check out.

-=Godoffire=-

Comments
ghost's avatar
ghost 18 years ago

nice

ghost's avatar
ghost 18 years ago

bravo! I commend you

ghost's avatar
ghost 18 years ago

thanks. i

ghost's avatar
ghost 18 years ago

woot i just made the .bat version of this:)

ghost's avatar
ghost 18 years ago

good job

ghost's avatar
ghost 18 years ago

good job, are you going to be doing an intermediate verson of your article?

ghost's avatar
ghost 18 years ago

i might. i also have phreaking 101. but what i am thinking of doing is to make a bunch of begainer articles and put them up on the web or in a book just to start people off. so far i have
Phreaking 101 batch Programing 101 i'm hoping to make a total of 14. you know enough to start someone off. i want to make one on makeing a computer. but so far thats all i can think of.

ghost's avatar
ghost 17 years ago

wow good job nice article well written very informative