Introduction: Comprehensive VBS and Batchfile Tutorial - Beginner to Advanced

About: All your base are belong to us.

This is my first instructable, so take it easy, and feel free to recommend any changes in future instructables.

In this instructable I will show you how to write various visual basic scripts (vbs) and batchfiles (bat), as well as how to interconnect the two, so to speak.  All of the example viruses are safe to run on your computer, however some of them (will be clearly stated) may crash your computer just by opening up too many windows at once.

I will provide both the source code and instructions on how to create/run/disable all of these viruses.  It is highly recommended that you read an entire step before trying to execute one of these, as some of them can be hard to stop.  At the same time, I assure you none of them will ruin your computer.  Of course, I take no responsibility for any of your actions, and if you write the code wrong and it does ruin your machine, that is not my fault, and I cannot be held accountable.  For any of the code throughout the entire instructable, just copy and paste.  It will save you a lot of time.

Please note that I am doing all of these on Windows XP, and some the commands may not be the same on other operating systems.  Anyway, enough of this gibberish, let's get to scripting!

Step 1: Basic VBS Messages

First off, I will show you many examples of different styles of error messages that can be useful for conveying different ideas or pranking different people.

Open notepad (if you don't know where that is, just go start->run and type "notepad.exe" without the quotes and hit enter).  Here are the different error codes and what they do.  By the way, just edit the original and change the number, as retyping all of these would take a LONG time.

text=msgbox ("Message",0,"Title")     -This is a basic message with a beep and an ok button.
text=msgbox ("Message",1,"Title")     -This adds a cancel button to the first one.
text=msgbox ("Message",2,"Title")     -This has buttons "abort", "retry", and "ignore", and the beep.
text=msgbox ("Message",3,"Title")     -Has buttons "yes", "no", and "cancel".
text=msgbox ("Message",4,"Title")     -Just the yes/no
text=msgbox ("Message",5,"Title")     -Retry/cancel
6 through 15 are exactly the same as 0
text=msgbox ("Message",16,"Title")     -This is the angry beep error message version of 0.
text=msgbox ("Message",17,"Title")     -16 with cancel button
text=msgbox ("Message",18,"Title")     -16 with abort/retry/ignore
Starting to detect a trend here?  It continues on like that.
text=msgbox ("Message",48,"Title")     -Different beep, and a yellow caution sign, with ok button.
Continues normal pattern from there.
At 64 we get a different beep and a question mark icon.

I know this is very boring, so I'll cut short here.
To run this, first save it as whatever.vbs  - make sure to select all file types, and not text files.
Then, just double click the vbs icon where you saved it.

Of course, you can change the message and the title to whatever you want.

Lastly, you can create loops in vbs like so:

do
msgbox "Hi"
loop

This is an infinite loop, but you can stop it with task manager.  Just go to processes and end the wscript.exe process.

Step 2: Basic Batchfiles

Batchfiles open a cmd window, also known as command prompt.  You can do many things with batchfiles that cannot be done with vbs files, so I always like to use a mix of both (which we'll cover later).

Open notepad again, or just remove the code from the previous step, and type the following:

@echo off          -This just tells the computer to not display the directory when you open the batchfile.
title Batchfile     -Any title you want
color 0a             -First digit is background color, second is text (this is green on black) (zero through F)
pause                -If you don't include this, the window will close instantly.

All this does is open a cmd window and says "press any key to continue......", and when you press a key, it closes.  You can mess around with the colors if you want.

Here are some basic cmd commands to add functionality to your batchfile.  Add any of them between the color line and pause:

echo Message     -Displays "Message"
dir     - displays the various folders in your main directory
dir/s     -goes through all folders and subfolders in the directory where the batchfile is located
dir/b     -removes header and other stuff (basic)
set     -displays lots of info about your computer
netstat -an     -displays all current tcp/ip connections and listening ports in numerical form
note: you can remove "n" if you don't want numerical form.
ipconfig /all     -displays info about your computer's ip address and host/server/default gateway, etc.
tracert     -traces route to specified ip address (put ip after "tracert " -with the space.
ping     -tests connection time to send a data packet to specified ip and get it back.  Put ip after.
start batchfile.bat     -starts a file called batchfile.bat (if it exists)

IMPORTANT NOTE: the above command, if typed in a file called batchfile.bat, will create an infinite loop, because each time it opens the window, the start command is re-executed and it opens another window - without closing the previous!  This WILL crash your computer if you don't hold down ctrl + c, which stops the code and closes them one by one.  Task manager won't help you.  However, don't fret.  Even if you crash your computer with this, it won't cause damage.  Just kill it with the power button before it gets too out of hand, let is sit for a minute, and boot it back up.

echo H
ping localhost -n .5 >nul        -these two lines send "H" to the computer you are on.

:1                                       -this creates an infinite loop of "Hi", which can also be stopped with ctrl + c
echo Hi
goto 1                                -you can use the goto loop for any command, but be cautious.

There are thousands of commands for batchfiles and command prompt, and I cannot go over them all here.

Step 3: Combining VBS and Batchfiles, and Opening Files

First of all, you are going to want both the vbs file and the batchfile in the same folder, or both on your desktop, or whatever, but they have to be in the same directory.

Now, you can initialize just about anything from a vbs file, including batchfiles, so we'll do it that way.  There are much more complex ways of doing it, but I won't go into that here.

To start, you will need to create a shell script.  It's easier than it may sound.  Just type the following as the first line of you .vbs file:

set wshshell = wscript.CreateObject("wscript.shell")

Now you can do all sorts of things with your script.  For examlpe, ghost typing (I'll get to batchfile initialization in a minute):

set wshshell = wscript.CreateObject("wscript.shell")
wshshell.run "Notepad"
wscript.sleep 2000
wshshell.AppActivate "Notepad"
wshshell.sendkeys"H"
wscript.sleep 145
wshshell.sendkeys"i"

This program will open notepad, wait a second or so, type H, wait a fraction of a second, and then type i.  Very fun for creeping people out, making them think someone has hacked their computer and started typing.

To open a batchfile called batchfile.bat, for example, type:

wshshell.run "batchfile.bat"

It's as simple as that.  You can open anything.  Now, to open a webpage, you're going to need to use the batchfile.  Just type the following to open google:

start www.google.com

You can use this for any url.  And it doesn't matter if you have the http:// part or not.  Either way works.

Step 4: Two Fake Viruses

Here are two examples of fake, harmless viruses that I created.  Feel free to test them out, they won't hurt you, just follow the instructions at the bottom of this step for closing/canceling the virus.

Example 1:

prank.vbs:

set wshshell = wscript.CreateObject("wscript.shell")
wshshell.run "Notepad"
wscript.sleep 2000
wshshell.AppActivate "Notepad"
wshshell.sendkeys"A"
wscript.sleep 145
wshshell.sendkeys"l"
wscript.sleep 101
wshshell.sendkeys"l"
wscript.sleep 125
wshshell.sendkeys" "
wscript.sleep 250
wshshell.sendkeys"y"
wscript.sleep 150
wshshell.sendkeys"o"
wscript.sleep 130
wshshell.sendkeys"u"
wscript.sleep 161
wshshell.sendkeys"r"
wscript.sleep 140
wshshell.sendkeys" "
wscript.sleep 185
wshshell.sendkeys"b"
wscript.sleep 150
wshshell.sendkeys"a"
wscript.sleep 112
wshshell.sendkeys"s"
wscript.sleep 136
wshshell.sendkeys"e"
wscript.sleep 145
wshshell.sendkeys" "
wscript.sleep 130
wshshell.sendkeys"a"
wscript.sleep 190
wshshell.sendkeys"e"
wscript.sleep 108
wshshell.sendkeys"r"
wscript.sleep 250
wshshell.sendkeys"{bs}"
wscript.sleep 90
wshshell.sendkeys"{bs}"
wscript.sleep 108
wshshell.sendkeys"r"
wscript.sleep 250
wshshell.sendkeys"e"
wscript.sleep 190
wshshell.sendkeys" "
wscript.sleep 130
wshshell.sendkeys"b"
wscript.sleep 161
wshshell.sendkeys"e"
wscript.sleep 140
wshshell.sendkeys"l"
wscript.sleep 152
wshshell.sendkeys"o"
wscript.sleep 150
wshshell.sendkeys"n"
wscript.sleep 129
wshshell.sendkeys"g"
wscript.sleep 200
wshshell.sendkeys" "
wscript.sleep 130
wshshell.sendkeys"t"
wscript.sleep 161
wshshell.sendkeys"o"
wscript.sleep 140
wshshell.sendkeys" "
wscript.sleep 118
wshshell.sendkeys"u"
wscript.sleep 150
wshshell.sendkeys"s"
wscript.sleep 250
wshshell.sendkeys"!"
wscript.sleep 500
wshshell.sendkeys" "
wscript.sleep 200
wshshell.sendkeys":"
wscript.sleep 300
wshshell.sendkeys"P"
wscript.sleep 500
wshshell.run "virus.bat"
wscript.sleep 700
text=msgbox("All Your Base Are Belong To Us",16,"You Have A Virus")
text=msgbox("Do you want to delete the virus?",20,"You Have A Virus")
text=msgbox("All Your Base Are Belong To Us",16,"Access Denied")
text=msgbox("All Your Base Are Belong To Us",16,"Access Denied")
text=msgbox("All Your Base Are Belong To Us",16,"Access Denied")
text=msgbox("Please wait while the virus is cloned repeatedly",16,"Cloning Virus")
wshshell.run "message.bat"
wshshell.run "batchfile.bat"
do
text=msgbox("And I win!",16,"You Lose")
loop

--------------------------------------------------------
virus.bat:

@echo off
title All Your Base Are Belong To Us
color 0a
cd..
cd..
cd..
:1
dir/s
goto 1

--------------------------------------------------------
message.bat:

echo off
title Greetings, Victim
color 04
do
echo You Have A Virus
ping localhost -n .5 >nul
loop
pause

-------------------------------------------------------
batchfile.bat:

start batchfile.bat

-------------------------------------------------------

NOTE:  This has the one I warned you about, start batchfile.bat in batchfile.bat.  Only run this if you know what you're doing!  Btw, cd.. in the virus.bat file goes up a directory path in cmd, which means you broaden your scope.  This will loop through all the files and folders on your computer continuously.  Very annoying, but it won't hurt anything.  And just remember these are all separate files in the same folder.  Also, the first thing this prank virus does is ghost type "All your base are belong to us", even with a typo and some backspaces to correct it, making it all the more believable that your victim was hacked.  It also has variable rates of typing, as indicated by the varying values for sleep.

Example 2:

prank2.vbs:

set wshshell = wscript.CreateObject("wscript.shell")
msgbox "Don't"
msgbox "You"
msgbox "Hate"
msgbox "It"
msgbox "When"
msgbox "This"
msgbox "Happens?"
wshshell.run "test.vbs"

----------------------------------------------------
test.vbs:

strSoundFile = "C:\fakevirusprank2\magicwrd.wav"
Set objShell = CreateObject("Wscript.Shell")
text=msgbox ("Do you want a puppy?",52,"Free Puppy")
do
strCommand = "sndrec32 /play " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, False
Wscript.Sleep 500
text=msgbox ("You didn't say the magic word",16,"You Do Not Get A Puppy")
loop

--------------------------------------------------
NOTE: The directory of the first line of test.vbs is wherever your sound file is.  My sound file is the Jurassic Park "Uhn uhn uhn, you forgot to say the magic word", and it loops, so it's really funny and annoying.  The first part displays a different message box each time they click ok OR close the window, then runs the second file.  The second file asks the victim if they want a puppy, no matter what they click, yes, no, or close, they get the Jurassic Park wave audio file and a corresponding error message.

All right, to disable the first one, undoubtedly the more dangerous of the two, first hold down ctrl + c right after the cmd windows start filling the screen.  Delay and you may be too late on some older computers.  Once it's stopped. close all the cmd windows individually and then open task manager.  You will need to end the process called "wscript.exe" that I mentioned earlier.  Then close anything else still open, and you don't need to save the text file ;)

To disable the second one, just open task manager and end wscript.exe.  Close everything that's open.  Piece of cake.

Step 5: Final Notes and Ideas

It is important to note that not all machines are created equal.  Some Operating Systems will use different commands, the ones I used were all Windows XP, and also work on many other Windows versions and some of them on Mac Linux.  If you are having trouble getting something to work, comment about it below, and I will help you as best I can.  You can also find a lot of this information on google and youtube.

Again, I take no responsibility for any harm that may come to your computer, as following my instructions correctly and carefully will not harm your machine.

If you have any ideas, questions, recommendations, suggestions, problems, curiosities, etc., feel free to comment below.  Just be descriptive and try not to misspell too much ;)  Please share with your friends!  (And prank them with these!)