• Game Rebels: The site that rewards you for posting
  • Join The Awesome ARK Server!

    Island PVE (Official Rates x2) by Vurh.Club
    Join ARK Server! Join ARK Discord!
  • The Game Shop V2!

    A Complete revamp! Hundreds of FREE games, now available!
    Shop Now!
  • Game Rebels Community

    Welcome to this awesome gaming forum
    Register Now
  • Earn Points to Buy Games!

    The more you post, the more you earn
    Learn More

The Monetizers - Ultimate Guide to Batch Scripting

Discussion in 'Coding Tutorials' started by Stealth, Feb 27, 2013.

  1. Stealth

    Stealth Active Member

    By: Stealth



    What is Batch?

    A History Lesson


    Writing Batch Files

    -Basic Commands/Your First Batch File

    -Spicing up your Batch File

    -Title Change
    -Color Command
    -Loading Effect

    -Start Command + How to open up a Website
    -User Variables/Interaction

    Dangerous Commands
    -Del (Delete)
    -Ren (Rename)

    Brewing a Virus

    Game Development
    -Deal or No Deal
    -Splat-the-Rat (Whack-a-Mole)

    Innovative Batch Files/Effects
    -Batch Keylogger
    -Matrix Batch Effect

    Batch File Makers

    Batch Virus Makers

    More Sources



    Ever wanted to know everything about batch? I don't mean the basics, I mean EVERYTHING. Well, you have come to the right place! This thread will leave you stuffed with information. By the end of this, your brain will be overflowing with knowledge.

    What is Batch?

    Well, Batch is a scripting language. Using Batch, you write a batch file, a compiled text file containing commands that will run in order. The name "Batch" was given to this language because a batch file contains a bundle or batch of commands. Batch files were made to finish tasks in a shorter period of time. Batch files also keep your operating system working. In every windows operating system, there is a least one batch file that is crucial to the operation of Windows.

    A History Lesson

    As the Windows OS evolved, so did the use of batch files. Long ago, in the early OS versions, batch files were extremely crucial. Early versions of Windows had batch files that actually made the OS start up properly. Over time, batch files became less useful. Windows could sustain most of its frame without the help of batch files. But in a couple of years, batch files became a source of entertainment. How? Well, some people saw the advantages to batch and its endless possibilities. Soon after that, a new era was born. People started making batch games, applications, and even found ways to create simple antiviruses with them. Batch files are still a popular success today. Without those brilliant minds, I wouldn't be writing this guide.


    So, most of you may know that all languages have requirements. Usually some special program. For example, C++ requires an IDE and a Compiler to work. So for Batch, is it the same? No. Not at all. All you need is:


    That's it! The only program you need is Notepad. If you don't know yet, notepad is already on your PC. Can't find it? Just go to Start Menu > All Programs > Accessories > Notepad. Now... are you ready to write a batch file?

    Writing Batch Files

    Basic Commands/Your First Batch File

    Ok, are you ready to write your first batch file? Let's get going! First off, open up Notepad.

    The first line of code we are going to learn is @echo off. Now what does this line do? Well, it stops your batch file from showing file paths. It makes your program look professional. Just make sure you have this in the first line of notepad.

    So, your notepad should have this in it:

    @echo off
    Now, have you ever wanted to make your program say something? Well if you do, you have to use the echo command. If I wanted my program to say "Hello World!”… I would type this on the second line of notepad:

    echo Hello World!
    So, now your notepad should have this in it:

    @echo off
    echo Hello World!
    Let's just say this is our program. Nothing else. If we saved it (you will learn how to later) and ran it, it would pop up then close in less than a second. Why?! Well, you forgot to tell the program to Pause! What, did you honestly expect it to pause by itself? So, how do you make it pause? Well, you just put the command pause on the next line. So your notepad should look like this now:

    @echo off
    echo Hello World!
    So what actually happens when the pause command is processed during the run? Well, your batch file will pause and a message will appear. Your batch file will say "Press any key to Continue." Then when you press a key, it will move on to the next line of code. If there is no code left, the batch file will close. This may be a bit confusing, but let's run it and you will understand this.

    So how do I run my program? Well, first you have to save it. Wait. I know what you’re thinking. You just going to go save it as a text document and then just open it. Yes, that is perfectly... WRONG! You don't save it as a text file. You must save it as a batch file! To do this, follow these three simple steps.

    Step 1: Go to File > Save as

    Step 2: Name your file but at the end of the name, insert ".bat" or your batch file will not work at all. For example, I can name it "My Program.bat" and that would work.

    Step 3: For the "Save as Type" select "All Files" not "Text Files."

    This is SUPER important. If you don't do this, it will be saved as a text document.

    There, you have just saved your batch file! Now it's time to run it. Go open the file you just saved. If it does not open, right click the file and select "Run as Administrator." Once it is open, it should look like this:


    First of all, CONGRATULATIONS! You have just made your first batch file! Now, do you see what the Pause command did? It made the batch file say "Press any key to continue..." Then you pressed a key, and it moved on to the next line of code, which is nothing, so it closed.



    How do I Edit my Batch File Again?

    Just right click your batch file and click "Edit." It will then open up in notepad. Make your changes and then go to File > Save. Then close notepad and run your batch file again. All your changes should come into action.

    My Batch File Won’t Run! HELP?!

    Make sure you are on an administrator account. If it is still not running, right click your batch file and click "Run as Administrator." The batch file should run. If it does run but it just closes automatically, then there is an error in the source code you wrote. Go back and check that again.


    Spicing up your Batch File

    I quite frankly have to admit that the batch file we made a few minutes ago was boring. Some plain grey text on a black background. Exciting.

    Well, let's change that! Let's spice up this batch file of ours. First of all, let's make it look much more professional.

    Title Change

    Run your batch file again and look at the title. It is C:/windows/system32/cmd.exe. Why? Well, when we run our batch file, it calls command prompt. Our batch file is run in command prompt. So cmd (command prompt) is the framework for our batch file. But how do we change this? Well, you just use the title command. Now what does the title command do? This is pretty obvious. It changes the title. So how do we use it? Let's say I wanted to change the title to "My Program." I would use this:

    title My Program
    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:

    @echo off
    title My Program
    echo Hello World!
    Now let's test it out. Save your source and then run the batch file again. Now look at the title. It has changed!


    Color Command

    How about changing colors? Yup, you can do that as well!

    But how? Well, you must use the Color command. This will be one of the most confusing things I teach you so hang in there. 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 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[/code]
    D = Light Purple
    E = Light Yellow
    F = Bright White
  2. overcast

    overcast Member

    Thanks for the tutorial. I have used AutoHotKey before for this type of the code. I have ignored the batch scripting for no idea why. I have found that these days people are getting into powershell scripting. So this can be another lesson which I would look forward to reaching if you can write it. Again thanks for adding those color codes I need to use them and test them.