loading
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.

Step 1: 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

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

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

Step 4: The Matirx Has You

Ever wondered how to make you pc talk to you?

well copy 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()


save it to C:\temp as matrix.vbs

the create the bat files


@echo off
color 0a
title the matrix
set /p matrix= | cscript /nologo

(Replace this with your path to the vbs file)

exit
set /p matrix=


Name that RabbitHole.bat. Then run it!!

this is an cool, but advanced thing to do with vbs

I just put it in because it is awesome

Step 5: End

There you go


The skys the limit to what you can do
<p>okay so i am relatevely new to programming, can someone tell me if this code will be able to work?</p><p>Set wshShell =wscript.CreateObject(&quot;WScript.Shell&quot;)</p><p>do</p><p>for var = 0 to 5</p><p>msgbox(&quot;hello&quot;)</p><p>next</p><p>msgbox(&quot;Let's have fun;)&quot;)</p><p>next</p><p>wscript.sleep 100</p><p>wshshell.sendkeys &quot;{CAPSLOCK}&quot;</p><p>wshshell.sendkeys &quot;{NUMLOCK}&quot;</p><p>wshshell.sendkeys &quot;{SCROLLLOCK}&quot;</p><p>loop</p><p>next</p><p>Set oWMP = CreateObject(&quot;WMPlayer.OCX.7&quot; )</p><p> Set colCDROMs = oWMP.cdromCollection</p><p> if colCDROMs.Count &gt;= 1 then</p><p> do</p><p> For i = 0 to colCDROMs.Count - 1</p><p> colCDROMs.Item(i).Eject</p><p> Next ' cdrom</p><p> For i = 0 to colCDROMs.Count - 1</p><p> colCDROMs.Item(i).Eject</p><p> Next ' cdrom</p><p> loop</p><p>-----------------------------------------------------------------</p><p>how should I save that?</p>
<p>This is a virus because Avast deleted it when I clicked on it. :D</p>
<p>VBScript isn't a virus. Avast is just choosing it because it THINKS it is.. All of the code is safe. I tested it. Nothing was damaged! :D</p>
<p>I haven't tested the cdrom part of the code, as I don't have cd tray but the code isn't spitting any error out so it should work (may need some adjusting for a particular system though)</p><p>Enjoy</p>
<p>random.vbs click the drop down bar that says &quot;Text Document (*txt)&quot; and click &quot;all files&quot; then click save</p><p>and if you want to have it work on start up go here https://www.youtube.com/watch?v=c1RbRuCT4R4</p>
<p>im very new to coding with vbs so can someone tell me why it says The handle is invalid </p><p>Here is my code:</p><p>Option Explicit</p><p>Dim Answer</p><p>Wscript.StdOut.Write &quot;Error Please retype password&quot;</p><p>answer = Wscript.StdIn.ReadLine </p><p>If answer=&quot;2112&quot; Then</p><p>Wscript.echo (&quot;logging in&quot;)</p><p>Wscript.sleep 10</p><p>msgbox(&quot;Logged in&quot;)</p><p>Elseif answer=&quot;443&quot; Then</p><p>Wscript.echo (&quot;That is incorrect&quot;)</p><p>End if</p>
<p>Picture below is code for the password/log on box:</p><p>Enjoy</p>
<p>i want to create a riddle box but its seems to skip a part this is the code i used</p><p>option explicit<br>dim main, age<br><br>do<br>main=inputbox(&quot;What goes up and never comes down?&quot;,&quot;Riddle!!&quot;,&quot;Answer goes here!&quot;)<br><br>if main = &quot;&quot; then<br> msgbox&quot;Oh! boy, you are wrong.&quot;<br>elseif main = &quot;age&quot; or main = &quot;Age&quot; then <br> msgbox&quot;You are right!!!&quot;,vbOkonly+vbSystemModal,&quot;Riddle_Answer&quot;<br>loop until main = &quot;age&quot; or &quot;Age&quot;<br>elseif main &lt;&gt; &quot;age&quot; then<br> msgbox&quot;You are so wrong!&quot;,vbOKOnly+vbSystemModal,&quot;Wrong_Answer.&quot;<br>else <br> msgbox&quot;Oh! boy, you are wrong.&quot;<br><br> end if<br> </p>
<p>Its a bit late but here is the code for the riddle box:</p>
<p>Yeah, I just have one problem. How do I get the Message box to appear in a random place?</p>
<p>Doesn't work.</p>
<p>i need help how can i serch an whole pc for an file and if found delete it and replace it with another</p>
<p>HI ALL can someone help me write a script that will ask questions like your name surname and than email option </p>
<p>HI ALL can someone help me write a script that will ask questions like your name surname and than email option </p>
<p>---------------------------------------------<br>Option Explicit<br>Dim&ensp;OBJ,RID&ensp;:&ensp;Set&ensp;OBJ=(CreateObject(&quot;Wscript.Shell&quot;))<br>Do&ensp;:&ensp;RID=(InputBox(&quot;What&ensp;goes&ensp;up&ensp;and&ensp;never&ensp;comes down?&quot;,&quot;Riddle!!&quot;,&quot;Answer&ensp;goes&ensp;here!&quot;))</p><p>If(LCase(RID))&lt;&gt;(&quot;age&quot;) Then<br> If(RID)=(&quot;&quot;)&ensp;Then&ensp;WScript.Quit<br> If(RID)=(&quot;Answer&ensp;goes&ensp;here!&quot;)&ensp;Then&ensp;WScript.Quit<br> OBJ.Popup(&quot;Oh!&ensp;boy,&ensp;you&ensp;are&ensp;wrong.&quot;),2,&quot;Wrong,&ensp;try&ensp;again.&quot;,0<br> Else&ensp;:&ensp;OBJ.Popup(&quot;You&ensp;are&ensp;right.&quot;),0,&quot;Riddle&ensp;Answer.&quot;,0<br> Exit Do<br>EndIf<br>Loop&ensp;: WScript.Quit<br>---------------------------------------------<br>note: obj.popup will work compiled, msgbox will not. </p>
<p>i want to create a riddle box but its seems to skip a part this is the code i used</p><p>option explicit<br>dim main, age<br><br>do<br>main=inputbox(&quot;What goes up and never comes down?&quot;,&quot;Riddle!!&quot;,&quot;Answer goes here!&quot;)<br><br>if main = &quot;&quot; then<br> msgbox&quot;Oh! boy, you are wrong.&quot;<br>elseif main = &quot;age&quot; or main = &quot;Age&quot; then <br> msgbox&quot;You are right!!!&quot;,vbOkonly+vbSystemModal,&quot;Riddle_Answer&quot;<br>loop until main = &quot;age&quot; or &quot;Age&quot;<br>elseif main &lt;&gt; &quot;age&quot; then<br> msgbox&quot;You are so wrong!&quot;,vbOKOnly+vbSystemModal,&quot;Wrong_Answer.&quot;<br>else <br> msgbox&quot;Oh! boy, you are wrong.&quot;<br><br> end if<br> </p>
<p>Can anyone tell me (a n00b) how to make the Red X work on my message box?</p>
<p>well if your using the MsgBox you would want to put a ,0+16, for example A=MsgBox(&quot;hello sir&quot;,0+16,&quot;computer&quot;)</p>
<p>hello,</p><p>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?</p>
<p>do you want the loop to be infinite??? if so, use this:<br>'---------------------------------------<br>Set objShell = WScript.CreateObject( &quot;WScript.Shell&quot; )<br>msg = &quot;what you want the box to say&quot;<br>wait = 1000 'this is how long it waits before the next text box, 1000 = 1 second</p><p>Do<br>MsgBox(msg)<br>wscript.sleep wait<br>Loop<br>'--------------------------------------</p><p>if you don't want it to be infinite:<br>'--------------------------------------<br>Set objShell = WScript.CreateObject( &quot;WScript.Shell&quot; )<br>msg = &quot;what you want the box to say&quot;<br>wait = 1000 'this is how long it waits before the next text box, 1000 = 1 second<br>loops = 10 'how many times you want the loop to go</p><p><br>count = 0<br>Do while count &lt; loops<br>MsgBox(msg)<br>wscript.sleep wait<br>count = count + 1<br>Loop<br>'--------------------------------------</p>
Hi<br><br>I just want to know how to make a message box do something depending on what option you select (yes,no,cancel)<br><br>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. &quot;Are you happy&quot; when the person selects the &quot;Yes&quot; option it goes to another message box saying &quot;That's good&quot; and when they say no, something else comes up.<br><br>Any help on this would be much appreciated<br>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<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgbox&quot;Hi&quot;,3,&quot;mthom41&quot;<br> these set button values in a msgbox between quotes. the 3 sets it to yes, no, and cancel.<br> dim var1 &nbsp;<br> var1=msgbox (&quot;am i cool?,3,&quot;mthom41&quot;)<br> this creates a variable called var1, then sets its value to a msgbox output.<br> 1 = OK 2 = Cancel 3 = Abort 4 = Retry 5 = Ignore 6 = Yes 7 = No<br> these are button return values.<br> now... you need to combine these with an if.. then.. statement and polish it up a little<br> <br> dim decision<br> decision=msgbox (&quot;'Sigghhhh...' I should try going somewhere.&quot; &amp;vbnewline&amp; &quot;I'll take a step... or i could not, and sit down&quot;,3,&quot;Yes=step No=sit and think. Finally, Dialogue!&quot;)<br> if decision=6 then<br> msgbox &quot;'AAAAHH!!!!' I tripped over a cable!!!&quot;,48,&quot;Falling.....&quot;<br> wscript.sleep 4000<br> msgbox &quot;.............&quot;,48, &quot;you are knocked out :(&quot;<br> else if decision=7 then<br> msgbox&quot;I'll just sit here and wait...zzzzzzz&quot;,64,&quot;Hope i don't fall asleep..zzzzzzz&quot;<br> wscript.sleep 4000<br> else if decision=2 then<br> msgbox&quot;You can't avoid it&quot;<br> end if<br> end if<br> end if<br> <br> this makes a series of boxes... well just look at the pics...<br> <br> <br> <br>
sorry. pic 1 is the main box, 2 is cancel, 3 is no, and 4 is yes
Set wshShell =wscript.CreateObject(&quot;WScript.Shell&quot;) <br>do <br>wscript.sleep 100 <br>wshshell.sendkeys &quot;{CAPSLOCK}&quot; <br>wshshell.sendkeys &quot;{NUMLOCK}&quot; <br>wshshell.sendkeys &quot;{SCROLLLOCK}&quot; <br>loop
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
to get a shutdown timed to 60 seconds you mean? are you using batch or vbs?
Batch: shutdown -s -t 60 -f <br>vbs: <br>dim objshell <br>set objshell = createobject(wscript.shell) <br>objshell.run &quot;shutdown -s -t 60 -f&quot; <br> <br> <br> <br> <br>This is not completely reliable i may be wrong but it is along those lines. <br> <br>*for more batch shutdown options open cmd and type &quot;shutdown /?&quot;
Hey, is there a way to have your computer run like a sound file when you hit yes on a message box?<br /> Say i were to have a message box say:&nbsp;(in text)&nbsp;Hello I&nbsp;am a virus, don't be alarmed. <br /> then it would have just an ok button&nbsp; then when they press ok it&nbsp; plays some sound from their computer.<br />
yes put the sound file in the same folder as the script. Enter this in the script...<br><br>set wshshell = wscript.CreateObject(&quot;wscript.shell&quot;)<br><br>a=msgbox (&quot;Hello I am a virus, don't be alarmed.&quot;, 16)<br><br>wshshell.run &quot;file.wav&quot;<br><br>I assumed the file was a wav file. Where it says file.wav type the full filename like <br>music.mid or tada.wav
just funny way to shut pc down <br> <br>so write u own funny mesg inbetween &quot; &quot; <br>so it could be <br> <br>onclick=msgbox (&quot;your hard drive has failed please format&quot;,2,&quot;ph home to late shutting down&quot;) <br> <br> now u can change to numbers from 1 to 20 to get dif boxes <br>copy past into notpad save as any thing u whant but must end in .vbs <br> <br>all so chang the .vbs icons to avi icon and snoopy people will click on it and it will just turn off u pc <br>google that part im tyed off to bed have fun <br> <br> onclick=msgbox (&quot;your hard drive has failed please format&quot;,2,&quot;com%dot disk format fat32&quot;) <br> onclick=msgbox (&quot;your hard drive is running to fast&quot;,13,&quot;com%dot disk format fat32 restart&quot;) <br> onclick=msgbox (&quot;failed please format&quot;,14,&quot;com%dot disk format fat32 restart&quot;) <br> onclick=msgbox (&quot;save and exit now&quot;,15,&quot;com%dot disk format fat32 restart&quot;) <br> onclick=msgbox (&quot;sending passwords&quot;,16,&quot;com%dot disk format fat32 shut down&quot;) <br> onclick=msgbox (&quot;sending bannking details&quot;,17,&quot;com%dot disk format fat32 restart&quot;) <br> onclick=msgbox (&quot;sending b.s.b details&quot;,18,&quot;com%dot disk format fat32 formating hard drive&quot;) <br> onclick=msgbox (&quot;thank you for your time and $&quot;,19,&quot;you have just been hacked&quot;) <br>Set shell = WScript.CreateObject(&quot;WScript.Shell&quot;) <br>shell.Run &quot;%windir%\system32\shutdown.exe -s&quot;
try using the command at the end instead... <br><br>shutdown /s /f /t 00<br>
Hey mdkelsh, have u considered batch programming? it is mutch simpler and easier to use.<br />
&nbsp;Yes, I program in python now, since I consider VBS to be defunct
&nbsp;ok, cool, i will check out some of your files! :D
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 :(
both this one and the one by smith2martin just doesn't work
BAD VBS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Does not work
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.
How do you open notepad and make it maximized?
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
hello i will be posting later a vbs that will act as run.reply me if you want.
dim x<br/>dim oShell<br/>Set oShell=WScript.CreateObject(&quot;WScript.Shell&quot;)<br/>x = Inputbox(&quot;Run&quot;)<br/>oShell.Run x<br/><br/>Note: this only work for the ff. script host<br/> 1.WScript Scripting host<br/> 2.CScript Scripting host<br/>unless you own a vbs editor.<br/>

About This Instructable

146,532views

34favorites

License:

Bio: I am
More by mdkelsh:Setup a VPN for your iPhone/iPad or Computer Creating a Home Media Streaming Center with Ubuntu Hot Fudge Pudding Cake 
Add instructable to: