Fun Tutorials!

VBS and Batch tutorials!

If you came to this tutorial section, that means you want to learn how to make some cool VBS and Batch programs. The skill level for these tutorials are beginner levels, so you will do just fine no matter how much computer experience you have!

Before we start though, we must make it clear what batch and VBS definitions are.

Batch: A very early script language that has started scince the times of MS DOS. It is responsible for executing a series of computer preinstalled commands. Some big programs use these batch scripts still to this day!

VBS: Visual basic script appeared in 1999 for Windows platforms. It is an easy language for use to make the computer do more complicated functions.


Lesson 1: Batch Message, VBS message

In this lesson, you will learn the following:

- Batch echo function

- vbs msgbox function

Our goal is simply to prompt the system to send a simple message using both of these script languages. Lets start off with batch.

Step 1:

Open notepad

Step 2:

Here is where you actually get to type stuff. Type this into notepad

@echo OFF
echo Hello World!

So far you should have something looking like this...

Here is what we are telling the program to do. First, we are telling it to not show us commands executed with the @echo OFF line. Second, we prompt the program to say Hello World! with echo. Echo is a simple function that prompts the program to say a message (or as programmers call it, string). The pause line is telling the program to stop continuing until the user presses a key. After the user presses a key, the program will go to the exit line which will close the batch script.

Next, we go to the top bar and click File, Save, or Ctrl S. Choose a location to save your batch in. Call the file Lesson1BATCH.bat and make sure you are saving as all files, not as text file. This is how the save setup should look like...

Once your batch is saved, you have to open a new notepad document to type in the VBS code. To do that click File, New. In the space you have, type:

x=msgbox("Hello World!",0,"Tutorial")

So far you should have something that looks like this:

Here is what we are telling the program to do. We are setting a variable called x which has the value of msgbox. Msgbox is a function in vbs which makes a windows message pop up on your screen. In the specifications for this message box (the brackets), we start off declaring that the message to output is Hello World! The quotation marks are to indicate that this text is a string (that means a variable which has text value, no numerical or other values). After that we put a comma, and a number. The number states what type of message box will output. 0 is a default message box with no icon or specific sound. There are other codes like 20 for critical message or 32 for warning but we won't do those in this lesson today. After the comma, we are putting another string value again (in quotations). We are naming the message box, and this message box will be called Tutorial.

Time to save the program. Go to File, Save or simply click Ctrl S. When prompted to save, call the file Lesson1VBS.vbs and make sure you are saving as all files, not text file. This is how the save set up should look like...

Now its time to look at our finished products!

First, try to open your batch file. If all goes right, it should look like this...

If you dont have what you see here, that means you made a mistake somewhere! If your program looks like this, well done!

Now, lets take a look at our vbs file. Try opening your vbs file and it should look like this...

Does it look like this? If not, go back and try to see what you have done wrong. If so, well done!

That covers our first lesson! We just covered the most basic of the basic in these two languages. In the next lesson, we will try and make things a bit more exciting!

Lesson 2: The fun stuff begins

In this lesson, you will learn the following:

- How to make basic loops in VBS and Batch

- How to create files with batch

- How to delete files with batch

- How to change colors with batch

- How to make a text to speech program with VBS

Our goal is to create a funny prank that we can use on our friends that can create and delete files, change colors, and say things out loud to the user

Step 1:

Open 2 seperate notepad windows

Step 2:

Now we will get to the actual coding part. You only need 1 of the notepad windows right now. The first file we will start with will be a batch.

Copy this into notepad (DON'T TYPE IT OUT! There are some invisible breaks between the lines):

@echo off
echo x=msgbox("Windows has encountered an error. Launch troubleshooter?",20,"Windows") > error.vbs
echo x=msgbox("Go back to Super RPG World 99 and press any key to open",20,"Windows") >> error.vbs
color 40
title Super RPG World 99
color 40
echo Launch Super RPG World 99?
echo Oops! Super RPG World 99 encountered an error.
echo To launch trouble shooter
start troubleshoot.vbs
echo We have encountered a fatal error within your drives
echo To launch advanced trouble shooter
color 10
echo ERROR
color 20
echo ERROR
color 30
echo ERROR
del error.vbs
goto 1



Now, dont worry. This isn't as complicated as it looks. There are a lot of new things for us here...

First off, lets start of with the cd statement. CD Makes the program's directory set to its current folder. We will need that when we are saving and deleting files in the local folder. Secondly, I'm going to go over the strange echo statements. What we are doing, is we are simply using the echo command from last lesson, but what is in the echo will go into a file. How to we declare that? Well, at some point in the command there is a > symbol, which will put all we just had in echo into error.vbs (which is right after the > symbol). The second echo statement does the same thing but into the second line of the file, using 2 > symbols (like this >>). In the echo statement we just have x=msgbox statements from VBS. We will need that for later on. Thirdly, we have color 40. What is color 40? Well, the color in batch files is actually sorted like this; first digit is the background color, and second digit is the text color. In batch colors, 4 is dark red and 0 is black. That means we have a dark red background and black letters. This is a full chart of colors on cmd:

Right after the color command there is title. Title sets the name for the window in windows. So when the program is open, it won't say command prompt, it will say Super RPG World 99. Now, we are skipping the echo, assuming you already know what it is. Going on to tree. Tree is a command that lists all the files in your folder and sub folders in a tree formation. All the main files in the folder will be on the "trunk" while folders in the folder will extend into "Branches" and the files in those folders will extend into "twigs". Since we have nothing in the folder, nothing will be displayed. But if there was something... you would get a pretty cool visual. Now, after the echo's, we see something called pause. Pause is a simple command that makes the rest of the program (beyond the pause) resume when you press a button on your keyboard. After that, we see a command that says start troubleshoot.vbs. We didnt make that file yet, but we need that start command there to execute the file once the program reaches the line. After a couple of pauses, we have :1. What this does is indicates a point or a "checkpoint" the program can go back to. then there is a color 10 command. We just changed the color to dark blue background and black text. We show a couple of error echo's to make stuff look scary, and some more color changes. after the last echo there is a del error.vbs command. It deletes the error.vbs the program made in the begining to clean up space. And when thats done there is goto 1, which tells the program to "go to" the point we made called 1. From :1 to goto 1, we created a loop of the commands inside.

By now you should have something that looks like this:

Lets save this as Super RPG World 99.bat. We will want to create a new folder, name it "game" or whatever you want, and save it in there.


Now, switch to your other notepad window. We will work on troubleshoot.vbs.


strText=("Welcome to trouble shooter")
strText2=("We have noticed that you have some missing drivers")
strText3=("Press ok to install drivers")
strText4=("Instalation complete. Please go back to the game")
strText5=("Oh, wait a second")
strText6=("error! beep beep! beep beep beep! peu peu poosh poosh! tink tonk! weeu weeu! lololol")
set ObjVoice = CreateObject("SAPI.SpVoice")
ObjVoice.Speak StrText
ObjVoice.Speak StrText2
ObjVoice.Speak StrText3
x=msgbox("Install Missing Drivers?",0,"TroubleShooter")
ObjVoice.Speak StrText4
ObjVoice.Speak StrText5
ObjVoice.Speak StrText6

There isn't much to this script, as it is very repetetive. We first list a couple of variables called strText(1-6). In each variable we make it equal a certain string (line of text). We will need these variables for later. Now, we have set ObjVoice, which makes a variable called ObjVoice. We make this variable contain a certain comamand. This command creates an object (hence the CreateObject) called SAPI.SpVoice, which is one of the pre installed voice programs for windows. Thats right, we will make the computer talk! Now, we tell ObjVoice to speak (we can only use speak because we made it equal an object called SAPI.SpVoice, which has speak as a command in it) the text in StrText, StrText2, and StrText3. After that we make a msgbox pop up which 0 in the middle of the brackets. If you remember, in the previous tutorial we had 20 instead of 0. 20 made an error symbol (red cross) window pop up, but the 0 value will make it a plain window with just an OK button. Now we make ObjVoice speak StrText5 and StrText6 until we reach DO. DO is a command that must always be capitalized, and is the start checkpoint of a simple loop. After DO we have the final ObjVoice statement that speaks StrText6, and after that we have LOOP. LOOP must also be capitalized, and it indicates the point where the program has to go back to DO.

You should have something looking like this:

Easy Right? Now save this in the SAME folder as you saved your batch.

Now its time for the Grande Finale! Open the batch on your friends computer and watch the results!

TO CLOSE THIS, open taskmanager, and find a process called wscript.exe. End it and the annoying voice will close.

Coming soon

More tutorials are coming soon! For now tell us how you liked the first one!