A Batch Tutorial 03-24-2012, 01:45 AM
#1
- Getting Started
In order to begin the scripting of a batch file, you must create a file. For this, you don't need a
special program or IDE, all you need is a basic text editor such as Notepad, which should come with
your Windows OS. For this tutorial, we are going to use Notepad to create our files. Firstly, you
must save a file as [anything].bat. For some versions, you may need to change the 'Text Documents
(*.txt)' to 'All Files'.
- Writing Scripts
After you have created your file, you can start writing code. Here are a few basic commands that will
help with your scripting...
Adding a comment to your code:
Print a line on the screen:
Setting a variable:
Functions and calling them:
Pausing the script:
Although not as refined, you can make a conditional statement. Here is an example of a login code:
You can actually create a file too:
Finding text in a file:
And lastly, quitting the console window:
- Conclusion
I hope you enjoyed reading this article, and if you are going to copy this, please give me some credit. I'd also like to mention that batch files are not sophisticated enough to create a virus, so any threads indicating the opposite are actually programs to annoy users, but not gain information of any sort.
P.S. - This is my first tutorial, so don't go around hatin'.
In order to begin the scripting of a batch file, you must create a file. For this, you don't need a
special program or IDE, all you need is a basic text editor such as Notepad, which should come with
your Windows OS. For this tutorial, we are going to use Notepad to create our files. Firstly, you
must save a file as [anything].bat. For some versions, you may need to change the 'Text Documents
(*.txt)' to 'All Files'.
- Writing Scripts
After you have created your file, you can start writing code. Here are a few basic commands that will
help with your scripting...
Adding a comment to your code:
PHP Code:
::not counted as part of the code
Print a line on the screen:
PHP Code:
echo Hello World!
::the below will print a blank line.
echo.
::another useful command for echo, is to disable the display of command that are being used.
@echo off
Setting a variable:
PHP Code:
::user input for the line below
set /P variable=
::also, setting one without user input
set variable=Hello World!
::you can print them too
echo %variable%
Functions and calling them:
PHP Code:
:function1
goto function2
:function2
Pausing the script:
PHP Code:
pause
::do it without prompting?
pause > nul
Although not as refined, you can make a conditional statement. Here is an example of a login code:
PHP Code:
@echo off
echo Password:
set /p pass=
if '%pass%' == 'world' goto correct
goto fail
:correct
echo yay!
pause
exit
:fail
echo boo!
pause
exit
You can actually create a file too:
PHP Code:
echo hello world > new.txt
::append to a file
echo hello world >> new.txt
Finding text in a file:
PHP Code:
find "hello" world.bat
And lastly, quitting the console window:
PHP Code:
exit
- Conclusion
I hope you enjoyed reading this article, and if you are going to copy this, please give me some credit. I'd also like to mention that batch files are not sophisticated enough to create a virus, so any threads indicating the opposite are actually programs to annoy users, but not gain information of any sort.
P.S. - This is my first tutorial, so don't go around hatin'.
To hack is a skill, but a skill may or may not be to hack.



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)