Rabu, 04 Mei 2011

What is Batch Programming and need for it


As I Promised the Fans of how to hack it that I am going to start with Batch Programming week, I am exactly doing the same. From now on I am going to write a new post on Batch Programming in every 2-3 days so stay connected , stay updated and read all the material in continuity to get the most out of it.
In case you havn’t  subscribed to how to hack it. till now you can do the same now to get updates of my upcoming posts through mail.

Batch Programming :-
Batch file programming is nothing but a batch of DOS ( Disk Operating System ) commands, hence the nameBatch programming . If you are into coding and know many languages you might have noticed that Operating System ( OS ) specific languages ( languages that work only on a particular operating system, eg: Visual Basic Scripting works only in Windows ) give you amazing control over the system. This is why Batch is so powerful, it gives you absolute control over DOS. Batch isn’t often used because it is OS specific, but it is fun and easy to learn. A well-conceived batch file is just the thing to automate the job you want to do.
Batch Files are stored with .bat extension.
To create a batch file follow the following steps..
1) Goto-> Notepad
2) Type Whatever you want ( the code you want to enter)
3) Goto-> Save as
4) Change the file type to all files and folder
5) name the file as anything you want with the extension .bat ,For eg…(“learnhacking.bat”)
I know this was not enough. But this was just the introduction part for beginners. I am sure it might have helped atleast someone. In My next post we will discuss various batch commands and code our first BATCH PROGRAM.
I hope you liked it, if you want more then make sure you subscribe to how to hack it.:)
Read more »

Learn Batch Programming Commands


Hey readers I am back with the Batch Programming tutorials. In my last post I told you guys about What is Batch Programming And Need For It. All those who havn’t read that post , pleast read it to get a more clear picture of the topic.
In this post we are going to code our first Batch Program. I am also going to tell you the most commonly used Batch Commands and their uses.

The first command you should know is ECHO. All ECHO does is simply print something onto the screen. It’s like “printf” in C or “PRINT” in Basic. Anyway, this is how we use it.
ECHO Hello World!
All right, now save the above line as a .bat file and double click it. This should be the output -
C:\WINDOWS\Desktop\>ECHO Hello World!
Hello World!
Did you notice that it shows the command before executing it. But we’re coders right? We don’t want our code to look so untidy so just add an @ sign before ECHO and execute it. The code looks much better. The @ sign tells DOS to hide from the user whatever commands it is executing.
Now, what if I want to write to a file? This is how I do it -
@ECHO Hello World > hello.txt
Simple huh? Remember, “>” to create or overwrite a file and “>>” to append ( write at the end ) of a file that already exists. Guess why this program wont work as desired to -
@ECHO Hello World > hello.txt
@ECHO Hello World Again > hello.txt
Looking at it, you will see that the program is supposed to write two lines one after another but it wont work because in the first line it will create a file called hello.txt and write the words “Hello World” to it, and in the second line it just over-writes the earlier text. So actually what it is doing is that it creates a file and writes to it and then over-writes what it had earlier written, to change this we just add a “>”. The additional “>” will make DOS append to the file. So here’s the improved form of the program -

@ECHO Hello World > hello.txt
@ECHO Hello World Again >> hello.txt
Save the above code as a .bat file and execute it, it will work without a hitch.
The next thing we should learn is the GOTO statement. GOTO is just the same as it is in BASIC or for that fact any programming language but the only difference is between the labels.
This is a label in C or BASIC – label:
This is a label in batch – :label
In C or BASIC, the “:” comes after the label and in Batch it comes before the label. Bear this in mind as you proceed. Here’s an example of the GOTO statement -
:labelone
@ECHO LoL
GOTO labelone
If you execute this code, you will see that it is an unlimited loop; it will keep printing to the screen till the end of time if you don’t interrupt it Smile The GOTO statement is very useful when it comes to building big Batch programs.
Now, we will learn the IF and EXIST commands. The IF command is usually used for checking if a file exists, like this -
@IF EXIST C:\WINDOWS\EXPLORER.EXE ECHO It exists
Observe that I have not used inverted commas ( ” ) as I would in BASIC or C.
The EXIST command is only found in Batch and not in any other language. The EXIST command can also be used to check if a file does not exist, like this -
@IF NOT EXIST C:\WINDOWS\EXPLORER.EXE ECHO It does not exist
Remember, Batch is not a language like C or BASIC or Pascal, it cannot do mathematical functions. In Batch, all you can do is control DOS. In the above example notice that there is no THEN command as there would be in most languages.
Sick and tired off using the @ sign before each and every command ? Let’s do some research, go to the DOS prompt and type in ECHO /? and press enter. Interesting, in this way, when you hear of a new DOS command you don’t know about, just type in “command /?” and you can get help on it. Now back to ECHO. According to the help we received by typing in ECHO /? you must have concluded if you type in ECHO OFF you no longer need to type an @ sign before every command.
Wait! just add an @ before ECHO OFF so that it does not display the message – ECHO is off.
The next command we are going to learn about is the CLS command. It stands for CLear Screen. If you know BASIC, you will have no problem understanding this command. All it does is clear the screen. Here’s an example -

@ECHO OFF
CLS
ECHO This is DOS
This command needs no further explanation but type in CLS /? to get more help on the command.
The next command we are going to learn is CD. It stands for Current Directory. It displays the current directory in which you are if you just type in “CD” but if you type in”CD C:\Windows\Desktop” it will take you to the Desktop. Here’s an example -
@ECHO OFF
CD C:WindowsDesktop
ECHO Testing.. > test.txt
ECHO Testing…>>test.txt
This will change the directory to the Desktop and create a file there called test.txt and write to it. If we had not used the CD command, this is how the program would have looked.
@ECHO OFF
ECHO Testing.. > C:\Windows\Desktop\test.txt
ECHO Testing…>> C:\Windows\Desktop\test.txt
See the difference? Anyway that’s all for the The Basics of Batch File Programming. Remember, each an every DOS command can be used in Batch..
I Hope you liked it.  I am sure you learnt something new.
If you want to Learn more then make sure you subscribe to how to hack it as I would be posting regular updates of the topic.:)
Read more »

Learn Batch Programming Commands


Hey readers I am back with the Batch Programming tutorials. In my last post I told you guys about What is Batch Programming And Need For It. All those who havn’t read that post , pleast read it to get a more clear picture of the topic.
In this post we are going to code our first Batch Program. I am also going to tell you the most commonly used Batch Commands and their uses.

The first command you should know is ECHO. All ECHO does is simply print something onto the screen. It’s like “printf” in C or “PRINT” in Basic. Anyway, this is how we use it.
ECHO Hello World!
All right, now save the above line as a .bat file and double click it. This should be the output -
C:\WINDOWS\Desktop\>ECHO Hello World!
Hello World!
Did you notice that it shows the command before executing it. But we’re coders right? We don’t want our code to look so untidy so just add an @ sign before ECHO and execute it. The code looks much better. The @ sign tells DOS to hide from the user whatever commands it is executing.
Now, what if I want to write to a file? This is how I do it -
@ECHO Hello World > hello.txt
Simple huh? Remember, “>” to create or overwrite a file and “>>” to append ( write at the end ) of a file that already exists. Guess why this program wont work as desired to -
@ECHO Hello World > hello.txt
@ECHO Hello World Again > hello.txt
Looking at it, you will see that the program is supposed to write two lines one after another but it wont work because in the first line it will create a file called hello.txt and write the words “Hello World” to it, and in the second line it just over-writes the earlier text. So actually what it is doing is that it creates a file and writes to it and then over-writes what it had earlier written, to change this we just add a “>”. The additional “>” will make DOS append to the file. So here’s the improved form of the program -

@ECHO Hello World > hello.txt
@ECHO Hello World Again >> hello.txt
Save the above code as a .bat file and execute it, it will work without a hitch.
The next thing we should learn is the GOTO statement. GOTO is just the same as it is in BASIC or for that fact any programming language but the only difference is between the labels.
This is a label in C or BASIC – label:
This is a label in batch – :label
In C or BASIC, the “:” comes after the label and in Batch it comes before the label. Bear this in mind as you proceed. Here’s an example of the GOTO statement -
:labelone
@ECHO LoL
GOTO labelone
If you execute this code, you will see that it is an unlimited loop; it will keep printing to the screen till the end of time if you don’t interrupt it Smile The GOTO statement is very useful when it comes to building big Batch programs.
Now, we will learn the IF and EXIST commands. The IF command is usually used for checking if a file exists, like this -
@IF EXIST C:\WINDOWS\EXPLORER.EXE ECHO It exists
Observe that I have not used inverted commas ( ” ) as I would in BASIC or C.
The EXIST command is only found in Batch and not in any other language. The EXIST command can also be used to check if a file does not exist, like this -
@IF NOT EXIST C:\WINDOWS\EXPLORER.EXE ECHO It does not exist
Remember, Batch is not a language like C or BASIC or Pascal, it cannot do mathematical functions. In Batch, all you can do is control DOS. In the above example notice that there is no THEN command as there would be in most languages.
Sick and tired off using the @ sign before each and every command ? Let’s do some research, go to the DOS prompt and type in ECHO /? and press enter. Interesting, in this way, when you hear of a new DOS command you don’t know about, just type in “command /?” and you can get help on it. Now back to ECHO. According to the help we received by typing in ECHO /? you must have concluded if you type in ECHO OFF you no longer need to type an @ sign before every command.
Wait! just add an @ before ECHO OFF so that it does not display the message – ECHO is off.
The next command we are going to learn about is the CLS command. It stands for CLear Screen. If you know BASIC, you will have no problem understanding this command. All it does is clear the screen. Here’s an example -

@ECHO OFF
CLS
ECHO This is DOS
This command needs no further explanation but type in CLS /? to get more help on the command.
The next command we are going to learn is CD. It stands for Current Directory. It displays the current directory in which you are if you just type in “CD” but if you type in”CD C:\Windows\Desktop” it will take you to the Desktop. Here’s an example -
@ECHO OFF
CD C:WindowsDesktop
ECHO Testing.. > test.txt
ECHO Testing…>>test.txt
This will change the directory to the Desktop and create a file there called test.txt and write to it. If we had not used the CD command, this is how the program would have looked.
@ECHO OFF
ECHO Testing.. > C:\Windows\Desktop\test.txt
ECHO Testing…>> C:\Windows\Desktop\test.txt
See the difference? Anyway that’s all for the The Basics of Batch File Programming. Remember, each an every DOS command can be used in Batch..
I Hope you liked it.  I am sure you learnt something new.
If you want to Learn more then make sure you subscribe to how to hack it as I would be posting regular updates of the topic.:)
Read more »

Batch File That Pops up with repeating messages


Hey guyz I hope you are enjoying my Batch Programming Series.
Before reading this post make sure you read my previous post you read my previous posts. You will get to know many posts about Batch Programmin. My first post What is Batch Programming And Need For It and the second one Learn Batch Programming Commands.
Now in this post we are going to make a batch file that pop ups with repeating message boxes.

below is the code for it.
:Begin
msg * Hi
msg * Are you having fun?
msg * I am!
msg * The admin of http://learnhacking.in!
msg * since you are stuck reading
msg * I am gonna teach you
msg * Batch Programming series
msg * Did you learn anything new
msg * and are you enjoying it
msg * if yes then do subscribe
msg * 
to learn hacking
msg * the fastest growing ethical hacking site
msg * on net
msg * and you know what
msg * you have been P-w-n-e-d with a capital “P”
GOTO BEGIN
See, its as simple as that. I am sure you might have understood. Now you can use this and irritate your friends or can play this trick anywhere you like.
Read more »

VISITORS

Flag Counter