Basics of .Batch files.
Batch files can be very useful for program installers. Many torrent downloaded games like Left 4 dead includes a batch file called install. but you might think.. yeah well :-\ it doesn't seem very easy!
well im going to teach you
In our document, we should start with something like this:
now that color code isn't important.. its just to make you love your program..Code:cls
@echo off
color B
if you do not know the codes for the color's just write blahblah where the B is and save the document.. now open.. this time it will be an list over color codes!
Well the basics of Batch:
Chapters
YOu can mark your own chapter by adding a line over the thing you want to be in the chapter like this
now our code should look like this:Code::chaptername
Ok. the next thing we should think about.. is adding new lines!Code:cls
@echo off
color B
:intro
New & Blank lines
To add a blank line with nothing on write this syntax:
notice that i wrote an dot.Code:echo.
but on lines you wan't your text on write like this:
Ok, so now our code should look something like this:Code:echo i like cookies
Pause!Code:cls
@echo off
color B
:intro
echo.
echo I like Cookies
You maybe have seen in programs the known "Press any key to continue...."
Thats very useful in programs with steps!
so the syntax for "Press any key to continue...." is actually very simple!
the code is.Code:pause
So now our code should look something like this:
.. Its kinda cool. but its kinda stupid that the screen doesn't clean itself?!Code:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
well the batch technology includes a fix for this!
and the new syntax im going to present for you is.... CLS
The CLS syntax will clean the screen for you!
the syntax looks like this:
So our code should look like this:Code:cls
GOTO >> ChapterCode:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
cls
The goto script is very awesome and effective.. instead of writing things thousand of times you can just use the GOTO script to get to a chapter.. make sure you create a new chapter for every thing you wan't to repeat.
The GOTO syntax must be written like this:
well lets try this out in our code!Code:GOTO <chaptername>
DeleteCode:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
cls
GOTO intro
The Delete code is very useful, often used in viruses and trojans.. and in antiviruses to remove the viruses.
The syntax for Delete is like this one:
the DEL syntax can also be like this:Code:DEL file.txt
BUT IT can also be:Code:DEL C:\Program Files\Windows Live\Messenger\licence.rtf
The last one deletes the hole folder.. But deleting folders must have verification! and someone told me they had problems with some permissions.. but this shouldn't appear.Code:DEL C:\Program Files\Windows Live\Messenger
so our code should look like this:
* I REMOVED the goto tag because it will loop the program.Code:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
cls
DEL momiloveyourcookies.txt
When the program has successfully deleted a file it will not appear on the program!
IF THEN COPY
Here is a syntax for looking for other files:
So our code should look like this now:Code:IF EXIST hot_cookies.txt COPY c:/some.dll %windir%/SYSTEM/hot_cookies.dll
But to make sure the program doesn't close by itselfCode:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
cls
DEL momiloveyourcookies.txt
echo.
IF EXIST hot_cookies.txt COPY c:/some.dll %windir%/SYSTEM/hot_cookies.dll
we gotta add this line at the end:
Already known if you have been reading my tut.Code:Pause
so the code looks like:
In the screenshot im removing the cls. so you can see hole the program you've created!Code:cls
@echo off
color B
:intro
echo.
echo I like Cookies
pause
cls
DEL momiloveyourcookies.txt
echo.
IF EXIST hot_cookies.txt COPY c:/some.dll %windir%/SYSTEM/hot_cookies.dll
pause
Screenshot of example:
http://i175.photobucket.com/albums/w...hotexample.png
But remember! this is a very simple example.. but its soo much to experience with the batch language..
Well that wasy everything for now!
Enjoy!
