Instructables
Picture of Fun with Easy VBS!!!
A Beginners guide to fun, and easy to do visual basic script. VSB may seem hard to some, but in fact it is really easy. Windows can even run it without a compiler! If you know javascript, it should be really easy for you.
 
Remove these adsRemove these ads by Signing Up

Step 1: Basic Message Boxes

Picture of Basic Message Boxes
Ok so lets go over the Basics.

Have you ever seen a message box like the one below,
you probaly have. These are used to alert users of whatever you want to say.

You can create your own by using the Function Msgbox

So the code to a message box that says hi would look like this,

Msgbox("hi")

Alternately you can make an unkillable message box by making a simple loop by using the Do, Loop commands.

Now that we covered message boxes, lets move to more advanced message boxes.

Step 2: Games and stuff

Picture of Games and stuff
If you ever wonder how to make text games than look no further. I might be wrong, but I believe that they used vbs. Now a lot of vb scripts use a compiler, but windows doesn't need one. Just type cscript before the file path, now if you know how to make bat files, then you can automate this process, but we wont get into that in this instructable.

Here is a little game i made

Option Explicit

Dim Answer

'types the question

Wscript.StdOut.Write "Nice Day Isin't it? "
answer = Wscript.StdIn.ReadLine

'if you type yes t

If answer="yes" Then
Wscript.echo ("I hope it stays this way")

'If you type no

ElseIf answer="no" Then

Wscript.echo ("I hope it gets better")

'anything else

Else

Wscript.Echo ("GoodDay to you")

'end

End If

now basically save this as .vbs and use the method before to run it.

Step 3: The Auto Typer

Picture of The Auto Typer
This code it to type something over and over again. I don't know how it is useful, but if you run it, you'll have to kill it in the task list

set shellobj = CreateObject("WScript.Shell")
shellobj.run "cmd"

do

shellobj.sendkeys "Y"
wscript.sleep 200
Shellobj.sendkeys "o "
wscript.sleep 200

loop

1-40 of 46Next »
HiddenHer01 month ago

hello,

Im trying to make a msgbox script where when you open it it says something like usual, then we you close it it waits a few seconds and opens again. Is this possible? if so can I have some help?

Riaan1113 years ago
Hi

I just want to know how to make a message box do something depending on what option you select (yes,no,cancel)

Say for example I make a message box and a person gives an input, depending on which input it will open another message box eg. "Are you happy" when the person selects the "Yes" option it goes to another message box saying "That's good" and when they say no, something else comes up.

Any help on this would be much appreciated
Thanks in advance
0 - ok button only 1 - ok and cancel 2 - abort, retry and ignore 3 - yes no and cancel 4 - yes and no 5 - retry and cancel
                                                      msgbox"Hi",3,"mthom41"
these set button values in a msgbox between quotes. the 3 sets it to yes, no, and cancel.
dim var1  
var1=msgbox ("am i cool?,3,"mthom41")
this creates a variable called var1, then sets its value to a msgbox output.
1 = OK 2 = Cancel 3 = Abort 4 = Retry 5 = Ignore 6 = Yes 7 = No
these are button return values.
now... you need to combine these with an if.. then.. statement and polish it up a little

dim decision
decision=msgbox ("'Sigghhhh...' I should try going somewhere." &vbnewline& "I'll take a step... or i could not, and sit down",3,"Yes=step No=sit and think. Finally, Dialogue!")
if decision=6 then
msgbox "'AAAAHH!!!!' I tripped over a cable!!!",48,"Falling....."
wscript.sleep 4000
msgbox ".............",48, "you are knocked out :("
else if decision=7 then
msgbox"I'll just sit here and wait...zzzzzzz",64,"Hope i don't fall asleep..zzzzzzz"
wscript.sleep 4000
else if decision=2 then
msgbox"You can't avoid it"
end if
end if
end if

this makes a series of boxes... well just look at the pics...



i1.JPGicancel.JPGino.JPGiyes.JPG
sorry. pic 1 is the main box, 2 is cancel, 3 is no, and 4 is yes
Set wshShell =wscript.CreateObject("WScript.Shell")
do
wscript.sleep 100
wshshell.sendkeys "{CAPSLOCK}"
wshshell.sendkeys "{NUMLOCK}"
wshshell.sendkeys "{SCROLLLOCK}"
loop
DJP4VEP5 years ago
you arnt actually teaching anyone how to create a script. what is the point in this instructable? im wanting to know what to put at the end of a fake virus script i have made in order to shutdown the computer after 60 secs. please help me
animan1 DJP4VEP5 years ago
to get a shutdown timed to 60 seconds you mean? are you using batch or vbs?
Batch: shutdown -s -t 60 -f
vbs:
dim objshell
set objshell = createobject(wscript.shell)
objshell.run "shutdown -s -t 60 -f"




This is not completely reliable i may be wrong but it is along those lines.

*for more batch shutdown options open cmd and type "shutdown /?"
UBERBANKAI4 years ago
Hey, is there a way to have your computer run like a sound file when you hit yes on a message box?
Say i were to have a message box say: (in text) Hello I am a virus, don't be alarmed.
then it would have just an ok button  then when they press ok it  plays some sound from their computer.
yes put the sound file in the same folder as the script. Enter this in the script...

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

a=msgbox ("Hello I am a virus, don't be alarmed.", 16)

wshshell.run "file.wav"

I assumed the file was a wav file. Where it says file.wav type the full filename like
music.mid or tada.wav
17hmr2433 years ago
just funny way to shut pc down

so write u own funny mesg inbetween " "
so it could be

onclick=msgbox ("your hard drive has failed please format",2,"ph home to late shutting down")

now u can change to numbers from 1 to 20 to get dif boxes
copy past into notpad save as any thing u whant but must end in .vbs

all so chang the .vbs icons to avi icon and snoopy people will click on it and it will just turn off u pc
google that part im tyed off to bed have fun

onclick=msgbox ("your hard drive has failed please format",2,"com%dot disk format fat32")
onclick=msgbox ("your hard drive is running to fast",13,"com%dot disk format fat32 restart")
onclick=msgbox ("failed please format",14,"com%dot disk format fat32 restart")
onclick=msgbox ("save and exit now",15,"com%dot disk format fat32 restart")
onclick=msgbox ("sending passwords",16,"com%dot disk format fat32 shut down")
onclick=msgbox ("sending bannking details",17,"com%dot disk format fat32 restart")
onclick=msgbox ("sending b.s.b details",18,"com%dot disk format fat32 formating hard drive")
onclick=msgbox ("thank you for your time and $",19,"you have just been hacked")
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "%windir%\system32\shutdown.exe -s"
crjeea 17hmr2433 years ago
try using the command at the end instead...

shutdown /s /f /t 00
nova4 years ago
Hey mdkelsh, have u considered batch programming? it is mutch simpler and easier to use.
mdkelsh (author)  nova4 years ago
 Yes, I program in python now, since I consider VBS to be defunct
nova mdkelsh4 years ago
 ok, cool, i will check out some of your files! :D
RedFlash4 years ago
Your code is loopy, when I executed it, my computer started going crazy. Scroll bars going loopy, when I tried to delete the file, it kept on opening it. I had to reboot my computer to stop it. Not good :(
Mirror Mage5 years ago
both this one and the one by smith2martin just doesn't work
BAD VBS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Does not work
geeklord5 years ago
Alright then. How do you get this "unkillable" box to go away without shutting down ur computer? Task manager isn't finding it either.....
A VBScript file is not an executable. The files are handled by the windows scripting host.. Kill wscript.exe
doesn't even pull that up
Make sure you are in the processes tab. What version of windows do you have? That's what it's called in XP (at least SP2)
Or, see if you can find cscript.exe in Task Manager. It is possible that it handles vbscript on your computer.
thx, got it now
Go to task manager, "Processes" tab, then find wscript.exe and kill it. This goes for all VBS running scripts.
will4215 years ago
How do you open notepad and make it maximized?
El Mano5 years ago
An interesting -ible for a programmer who knows the basic structure and operation of VBS. As for me, all I can do is get my computer to display a basic Message Box that I isolated from a VBS password-protection program. Perhaps you could write an instructable that will explain how VBS works: how to set and use variables, program organization, and the like. Then you could put a list of commands like "Msgbox("hi")" at the end, so instructees could learn how to construct a basic program and then have a quick reference of functions. Show people how to use a command and why it works, instead of simply saying "This creates a message box! Have fun!"
agreed
I don't get it explane it more simply
nativman5 years ago
hello i will be posting later a vbs that will act as run.reply me if you want.
dim x
dim oShell
Set oShell=WScript.CreateObject("WScript.Shell")
x = Inputbox("Run")
oShell.Run x

Note: this only work for the ff. script host
1.WScript Scripting host
2.CScript Scripting host
unless you own a vbs editor.
geeklord5 years ago
How about hte little bubbles that pop out of the right side of the toolbar?
twenglish15 years ago
this is awesome but i have one thing to say at the begining you typed vsb and im pretty sure you meant vbs(its in the intro)
im not listening to you any more. as soon as i tried to save the matrix, my pc started typing random things in the command line thing
awkrin6 years ago
and this thing IS dangerous. if u end the program too early, it will "type" space and backspace in whatever window u are.
it sayas for the matrixs thing no script verifyed!
for me it ran too fast
(removed by author or community request)
mdkelsh (author)  YummyPancakes6 years ago
I changed it
Did you explain this?

option explicit
On Error Resume Next

' declare variables
dim wshshell, title, mystring, length, position, tmp, loopA, loopB, linesToWrite, columns, objUser, objSysInfo, myName, myNameLength, col1, col2, col3, col4, col5, maximum, elements

set wshshell = wscript.createobject("wscript.shell")
title = "the matrix"

wshshell.SendKeys "{ALT}"+"{ENTER}"

' get user info, used to get the name
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

' ---------------------------
sub waitfor(var)
' set up window, set title, wait for it to complete
tmp = false
do until tmp
wscript.sleep 1000
tmp = wshshell.appactivate(var)
loop
end sub

' ---------------------------
sub matrix(elements)
' print random numbers to make "the matrix" look
' assumes elements is divisible by 5
columns = 5
col1 = true
col2 = true
col3 = true
col4 = true
col5 = true
randomize()
linesToWrite = elements / columns
for loopA = 1 to linesToWrite
for loopB = 1 to columns
Select Case loopB
Case 1
If col1 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 2
If col2 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 3
If col3 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 4
If col4 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
Case 5
If col5 = true Then wshshell.SendKeys Int(Round(rnd())) & "{TAB}" Else wshshell.SendKeys "{TAB}"
End Select
wscript.sleep 5
next
wscript.Echo

' This flip-flops columns to display 20 percent of the time, independently of each other.
maximum = 0.20
If rnd() < maximum Then
If col1 = true Then col1 = false Else col1 = true
End If
If rnd() < maximum Then
If col2 = true Then col2 = false Else col2 = true
End If
If rnd() < maximum Then
If col3 = true Then col3 = false Else col3 = true
End If
If rnd() < maximum Then
If col4 = true Then col4 = false Else col4 = true
End If
If rnd() < maximum Then
If col5 = true Then col5 = false Else col5 = true
End If
next
wscript.Echo
wscript.Echo
end sub

' ---------------------------
sub key(msg)
' do printouts of "the matrix" messages, and erase them
wscript.sleep 1500
length = len(msg)
for position = 1 to length
wshshell.SendKeys mid(msg, position, 1)
wscript.sleep 250
next
wscript.sleep 3000
for position = 1 to length
wshshell.SendKeys "{BACKSPACE}"
wscript.sleep 75
next
end sub

' ---------------------------
' start "main" execution here

waitfor(title)

For loopA = 1 To 4
Select Case loopA
Case 1
mystring = "wake up, Neo..."
Case 2
mystring = "The matrix has you..."
Case 3
mystring = "Follow the white rabbit..."
Case 4
mystring = "Knock knock..."
End Select
' now print out the correct string
key(mystring)
next

'_ _ _ _ _ _ _ _ _ _

wscript.quit()

I think not. You always have to ask yourself: Would an absolute beginner be able to use this information? This isn't Myspace. It's Instructables. This has no instruction, so isn't technically an Instructable. Please correct me if I'm wrong.
1-40 of 46Next »