Login Register


[TUT] All you need to know about Batch![TUT] filter_list
Author
Message
[TUT] All you need to know about Batch![TUT] #1
Alright I lied...Not ALL you need to know about batch, but a good deal of it
Biggrin

I see a lot of people, copy and pasting code and a "l33t ub3r hax v1ru5" and saying they know batch. When really, not a lot of people do.....but on the contrary....a lot of people DO know batch, without even knowing it!! Every time you use the command prompt in windows, you're using Batch!
Now with all this said, here comes a REAL tutorial on Batch scripting.

Things you need to know before starting to learn Batch/DOS
1. DOS does NOT stand for "Denial-of-Service Attack" so if you think it does, gtfo.
2. Batch is a SCRIPTING language, not a PROGRAMMING language.
3. Batch is one of the easiest languages to learn.
4. Batch only works on Windows, and Windows ONLY.
5. The linux form of Batch is "Bash" and has file extension .SH and is NOT interchangeable with Batch.
6. Batch CAN incorporate other SCRIPTING languages, such as VBScript, and JScript.
7. VBScript is Visual Basic Scripting, a VERY simple form of Visual Basic with no Dependencies. With extension .VBS
8. JScript is Java Scripting, A more simplistic form of Java. Requires Java/JDK. With file extension .JS
9. You cannot make "Programs" with Batch. As it is a Task Automation Scripting Language.
10. You'll become addicted to Batch.

Things you will need before starting to learn Batch/DOS

1. Notepad ++ Download it HERE
2. Literacy in the ENGLISH language.
3. Basic troubleshooting skills.
4. This tutorial Smile
5. L33T UB3R H4X0R 5K33LZ
6. A sense of humor for skids^

Now! It's time to start learning some Batch! :epic:

Open Notepad++ Go up to Language > B > Batch
It'll help you bunches!

The first and most important thing you need to know about Batch is directory hide/show.

ALWAYS start your batch file off with @echo off
Code:
@echo off pause

You'll that i put you commands here.
What do these commands do?

@echo off-tells the system to hide the current directory in the CMD that is being used. Making it more clean and easier to use.

Pause- Keeps the CMD window open, preventing a 0.25 second batch windows. Will display "Press any key to continue" Then after you press a key, it will continue with the code after it...unless there is none, then closes the Window.

So all languages start with "Hello World" for some odd reason...fuck it.

Code:
@echo off echo. echo Hello Hack Community! echo. echo Jacob here, teaching you guys Batch :D pause

This will show text in the CMD Window when ran.

Quote:Hello Hack Community!

Jacob here, teaching you guys Batch Biggrin
Press Any Key to Continue...

So you're wondering...why the extra "echo."'s right?

When you want to imitate an extra line when putting text on screen, you will type "echo." then continue to the next line. It will show as a blank line in the window. Go ahead, try it yourself Smile

Okay So now that you've figured out how to use the ECHO command and PAUSE command, you might be thinking..hmm i dont like "Press any key..." being there when i use PAUSE; or you may want to use your own message.

LUCKILY! Batch has one for that. Its the NUL suffix.

When you DON'T want something to show on the screen, or want to hide the fact that it is doing it, you will use >NUL after the command.

I'll demonstrate on PAUSE and ECHO text.

Code:
@echo off ::Remember to always start with @ECHO OFF echo. echo. You won't see this text on screen! >NUL ::You won't see the text above this. echo. echo Nothing above this text is there? ;) echo. echo Nor anything below this text. ::or text below this. PAUSE >nul ::pause >nul hides the "press any key to..." text and shows nothing but a flashing cursor.

So now its time for you to TYPE this text into Notepad++
If you really want to learn, you will TYPE it, not copy/paste it.

Now that you've typed it into Notepad++ and have run it. You've seen what it does. Time to explain

What do these codes do?
::-Leaves the coder messages in the script. Is not used by the command line at all. Its similar to // in c++ and /**/ in Java.

>NUL-Hides that line from the command line. NUL can be used on ANYTHING, not just text. ie (ping localhost -n 1 >nul) does the pinging, but doesnt show the pinging. CAN be used to imitate timers and set timed pauses.

Next Section! Biggrin






Run your batch file again and look at the title. It is C:/windows/system32/cmd.exe. Wonder why? When you run a batch file, it calls the Command Prompt, from that directory. What does the Title command do? It changes the title. So how do we use it? You'll see.

Code:
title (your title here)

It is as simple as that! But where do you put it? Well, let's just put it right after @echo off. So now your batch file source code should look like this:


Code:
@echo off title Learnin titles BREH echo Hello World! echo Still learning Batch i see :) pause

Now let's test it out. Save your source and then run the batch file again. Now look at the title bar.

ALRIGHT, MOVING ONWARD AND UPWARD! Biggrin




You can even change the color of your text and background in batch! Biggrin

For this you must use COLOR as your command. The parameters and syntax are below. The color command is pretty simple. You use the word "Color" and you add to 2 characters (a letter or a digit) to change the color. Here is a list of the available color codes:

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


So the command looks like this:


Code:
Color [][]

or a real example

Code:
color FB

Where do I put this? Anywhere, AS LONG AS it is BEFORE the first line of "ECHO" or "ECHO."


Code:
@echo off title (your title) color 0a echo Hello World! pause

Time to learn the START command(:

You can open ANY file on your computer, and even open internet, and even better, you can open internet to a certain page, or possibly a file such as .jpeg in your browser! USING BATCH! Sadly though...you MUST add file paths for this to work, although most windows-built-in programs, such as internet explorer, notepad, wordpad, etc, you WON'T need to add the file path! <33

To open notepad ONLY. Meaning, the batch will open, execute notepad.exe, and close immediately. You will use this command. (The START command.)

Code:
start notepad.exe


If I wanted to open up Internet Explorer, you would use this:

Code:
start iexplore.exe

If you wanted to open up a specific website you would use this (but with the link changed):


Code:
start iexplore http://www.hackcommunity.com

"http://www." MUST be before your link, or else, it will try to open "hackcommunity.com" inside of internet explorer, from the directory you're launching from. (.com is a file extension type, similar to .exe) Which is why. You MUST tell CMD that it is a webpage using HTTP://www.

You can open anything, even pictures. So lets say you wanted to Smile

Scenario: The picture is on your desktop.

You right click your picture, and youll see "Location: c:\users\%user%\desktop\picture.jpg"
That would be your directory for that (different in vista and 7)


Code:
Start C:\Users\%user%\Desktop\picture.jpg

And there is your picture ^.^


Time to learn the MOST TIME SAVING COMMAND.....Loops

These are pretty useful when you think about it. Ever wanted your batch file to do something forever? Instead of copying and pasting lines over and over again, you can just use a loop.

All you need is two commands to make a loop. Those two commands are the label (:x) command and the goto command. So let me show you an example.

Code:
@echo off :loop echo You will see this over and over. goto loop

:loop is a label. You use the colon (Smile and then name the label. To close the loop,you just use the goto command. When time comes, thhe CMD will ignore ":loop" and continue, until it hits GOTO LOOP, then it'll be all like, "HEY I GOTTA GO BACK...FUCK THESE COMMANDS, I GET TIRED OF RUNNING BACK AND FORTH D:"

Now this command has a dark side too. Be careful. For example, if you make the batch file start a memory consuming program over and over, it can hurt...such as

for this to even work, the file must be titled "fork.bat"
Code:
@echo off :fuckedbomb explorer call fork.bat goto fuckedbomb
DO NOT RUN THIS! ITS CALLED A FORK BOMB.

Will be updating soon enough. I dont wanna type a tut, i wanna keep up my studies for AU3 and the C/Java languages.

Reply

RE: [TUT] All you need to know about Batch![TUT] #2
Nice guide! +rep for you!
[Image: Signature.png]

Chek Out My Tutorials
| Set Up A Pentest Lab | How To Make Bitcoins |

Reply

RE: [TUT] All you need to know about Batch![TUT] #3
:ok::ok: very good for newbie :ok: nice job!

Reply

RE: [TUT] All you need to know about Batch![TUT] #4
and its only getting bigger! Biggrin

Reply

RE: [TUT] All you need to know about Batch![TUT] #5
Nice Tutorial. Good for the Batch Scripting Newbies.

Reply

RE: [TUT] All you need to know about Batch![TUT] #6
sorry i havent updated this in a while guys, been busy with autoit3

Reply







Users browsing this thread: