Instructables
loading
loading
Picture of How to: Make a message box using VBScript
In this "Instructable" I'll be showing you how to make a message box in Notepad using VBScript Coding.

Please Note: This is a completely harmless project and if something DOES go wrong, I will not be help responsible.


 
Remove these adsRemove these ads by Signing Up

Step 1: Step One

Picture of Step One
First thing to do is locate your Notepad.exe.
This application is on every windows computer OS and can be used for loads of interesting things.
Notepad.exe is normally located in Start Menu>All programs>Accessories


Step 2: Step Two: The code.

Picture of Step Two: The code.
For this next bit, it's fairly simple, because I do all the work.

x=msgbox("Your Text Here" ,0, "Your Title Here")

Make sure that the " is included in the text and replace the Your Text Here and Your Title Here. But don't change anything elese!

Advanced users can change something else.
  • 0 =OK button only
  • 1 =OK and Cancel buttons
  • 2 =Abort, Retry, and Ignore buttons
  • 3 =Yes, No, and Cancel buttons
  • 4 =Yes and No buttons
  • 5 =Retry and Cancel buttons
  • 16 =Critical Message icon
  • 32 =Warning Query icon
  • 48 = Warning Message icon
  • 64 =Information Message icon
  • 0 = First button is default
  • 256 =Second button is default
  • 512 =Third button is default
  • 768 =Fourth button is default
  • 0 =Application modal (the current application will not work until the user responds to the message box)
  • 4096 =System modal (all applications wont work until the user responds to the message box)
Change the "0" with any of these numbers above.

Step 3: Step Three: The Saving

Picture of Step Three: The Saving
Now for this bit, you would think that this is easy, but it's not as simple as Save As.

When you have finished the code, go to Save As and save it as: What You Want To Call It.vbs
At the end of the name, make sure that .vbs goes at the end and safe it anywhere.





Step 4: Step Four: Lets test it!

Picture of Step Four: Lets test it!
Now that we have completed the following steps, lets test it. Locate your safe file and dubble-click it. Lets see what the outcome was.



Step 5: Outcome.

Picture of Outcome.
The outcome of todays lesson was:

Your learned how Notepad.exe can become a powerfull scripting program
How to make a message Box
The values of Message Box's to make them look convincing.

Thank you for reading this lesson

JoshJarvis222 months ago
Oh, I understand... Hmmm, well I have to think about that scenario as far as I know there isn't a solution for what you'd like to do - would you like to have the end user always receive a message when trying to open a given local folder before they save to that folder? You might be able to create a script and have it monitor if two or more instances of explorer.exe proceses are running (one is always running if someone is logged in, but if two or more are open by the same user then display a message. You won't be able to know what folder they opened that easy and after making the script it would be better to make it a 'service' instead of another process, it could be done.) There also MIGHT be a GPO in which you could set rules on folders or particular folders to run a cha script when launched? I've never had that request yet.
NoviceGuyCC162 months ago

This works perfectly for making the simple (just "OK" reminder) message box I need, but can anyone tell me how to make the message activate? I specifically want the msgbox I created to pop-up when a general folder is opened. Can't seem to find a way to "activate" the msgbox in the folder's settings...

You would have to open a folder using a script to accomplish this, something like this:

x=msgbox("Would you like to open the Windows folder?" ,4, "Question:")

If x = vbNo Then Wscript.Quit(0)

If x = VbYes Then

Set WshShell = CreateObject("WScript.Shell")

X = WshShell.run("cmd /c explorer.exe ""C:\Windows""",0, true)

End If

Thank you for taking the time to reply. I'm an extreme novice with this stuff, but don't think this is what I was looking for. Let me know if I'm mistaken:
- I copied/pasted everything you put into Notepad and saved as a .vbs file. Then when I click on that file, it asks if I want to open the Windows folder (and gives me a yes or no options). When I click "yes" it opens the folder C:/Windows. This all sounds like how the example was designed to work.
- However, what I was hoping for was a way to show a pop up message WHEN I CLICK ON A FOLDER. An example would be if when I click on a "Pictures" folder I created, I want a pop up box to trigger and say something like "Reminder:" and "Remember to put new pictures on external hard drive" and then just have an "OK" option. That way, I'll remember to save my pics to my external hard drive every time I click on the "Pictures" folder. This is just an example, I really want to use if for work where I have customer's folders that contact past proposals, reports, documents...and a few of them require certain things like "must include sales tax on proposals," or "This customer has 10% Discount on all orders" - so I want everyone in my company to see these kinds of reminders when clicking on their folders in Windows Explorer.

It sounds like what I want is the other way around from what you said, so while your way lets me click on the VBS file, then click yes to open the example folder, my hope is to swap that around (click on a folder and then have a pop-up box show up to remind me certain things). Maybe some minor tweaking is what is needed.

Thanks again and if you have an answer to my follow up question, please let me know. Appreciate your help.
jairo12 years ago
christophor or anyone, could you please give an example with more lines.

I created a batch file that works fine using the single line text format you gave, but I cannot get it to work with 2 or more lines. Your help would be greatly appreciated.

Ultimately, I'd like the .bat file to create the msgbox with title and multiple lines.

The only reason I wouldn't use a Batch file to open a VBS file is because you will see the Command window in the background but if you want to relate VBS to Batch File you can do the following:

strMB = inputbox("Please enter your message here:")

Set WshShell = CreateObject("WScript.Shell")

WshShell.run "cmd /c @echo msgbox " & """" & strMB & """" & ",4096,""VBS2CMD2VBS:"">C:\Message.vbs",0, true

WshShell.run "C:\windows\system32\wscript.exe C:\Message.vbs",0, false

Wscript.Quit(0)

Now what we just did was pass the Variable on to another VBS using the Command line, or in essence a Batch file, you could do the same thing, the 1st script then called the VBS you just made. I am just showing you how complex you can make it and that you can execute anything in VBS that you can from a command line, but you can accomplish the same effect with less code like this:

strMB = inputbox("Please enter your message here:")

msgbox strMB, 4096, "Message"

PrasunU3 months ago

I selected option as 4. like Yes and No. But I want an website to open if clicked NO.

Can you please help?

PrasunU,

you can use any of these methods (I just think it's good to know different ways that work):

(A)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then MsgBox "You selected 'No'", 4096, "No:"

If x = VbYes Then MsgBox "You selected 'Yes'", 4096, "Yes:"

(B)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then

MsgBox "You selected 'No'", 4096, "No:"

Wscript.Quit(0)

End If

If x = VbYes Then

MsgBox "You selected 'Yes'", 4096, "Yes:"

Wscript.Quit(0)

End If

(C)

x=msgbox("Would you like to continue?" ,4, "Question:")

If x = vbNo Then

MsgBox "You selected 'No'", 4096, "No:"

Else

MsgBox "You selected 'Yes'", 4096, "Yes:"

End If

Wscript.Quit(0)

PrasunU PrasunU3 months ago

Attached is my vbs script.

CATW.vbs68 bytes
DanG133 months ago

Fantastic. But how do I kill it after 1 second?

Good Question DanG13! Here you go the 5 will kill it in 5 seconds:

Set WshShell = CreateObject("WScript.Shell")

x = WshShell.Popup("Would you like to continue?",5,"Title:",4)

If x = vbNo Then Wscript.Quit(0)

If x = VbYes Then

'Your script goes here

msgbox "you selected YES!", 4096, "Yes"

End If

How to use this with newline?

The answer is VbCrLf but you will have to add it to what you already like this: "text1" & VbCrLf & "text2" & VbCrLf & "text3", 0, "title"

Example:

x=msgbox("Would you like to continue?" & VbCrLf & "If you select No, you will see NO" & VbCrLf & VbCrLf & "If you select Yes, you will see YES",4, "Question:")

If x = vbNo Then

MsgBox "NO", 4096, "No:"

Else

MsgBox "YES", 4096, "Yes:"

End If

JoshJarvis222 months ago
fabian.a made it!5 months ago

Did it! Thanks a lot. Now I can make error messages!

vbs.png
CarysC5 months ago

thanks

MrSecurity1 made it!7 months ago

Here is something cruel you do to your friends (if you have any)! What this does is loops the box. So when they press "OK", it closes then opens again. Also, because it's "4096" it sits ontop of everything, just being awkward. Have fun!

Do
MsgBox"Just here to be awkward!",4096,"Troll v6.9.6.9.6.9.6.9.6.9"
Loop
Untitled.png
RthrG9 months ago

Don't put >"msgbox.vbs in the actual notepad, thats what you save it as, what I do is paste this MsgBox(" ",0+0," ") but of coarse there are no spaces in the final copy, then I just fill it in

um... yeah you got an error didn't you?

try this and then you will not have an error...

x=msgbox (“whatever you want message box to say here” ,0, ”title here”)
> “msgbox.vbs”

no, thats an error in a command line, you should had an error on one of your commands

lemonie5 years ago
Notepad isn't a "powerful scripting program" it's a simple text-editor.

L
IMHO A simple Text editor is a powerful programming tool. It used to be all there was. If you know what you're doing, a text editor might be all you need.

try this from a windows command line. do it from a directory where you have write permissions.


Type
c:\scripts> echo x=msgbox("Your text here." ,0,"Title here")>mbscript.vbs


Type
c:\scripts> cscript mbscript.vbs


You've just written a vbscript without any text editor at all.
to add more lines use >> instead of > before the file name.


Notepad, edit, vi, emacs whatever you use, a text editor IS a powerful tool.
after it creates the mbscript.vbs file how do you write into the newly created vbs file with code?

lets say...within that file i want to create a code that tell a program to run
Tell me what you're trying to do. So I can answer the question most thoughtfully.

I think I understand, but I want to be sure before I write up a bunch of stuff you don't need.

Thanks.
using your code
*************
c:\scripts> echo x=msgbox("Your text here." ,0,"Title here")>mbscript.vbs
***********

it creates an empty vbs script called "mbscript"...................now after it has done so, how do i write a code (from the same notepad i used to create the mbscript.vbs) in addition that fills the empty mbscript.vbs with a code to lets say...run another program?
Make sure you're at the command prompt.

You can get there like this:

go to start
then run
then type CMD
and hit enter

that will open the command line. It's a black screen with a blinking cursor and something like

C:\>_ the underscore represents the cursor. you don't type "c:\>"

you type only the following that is between the outer most quotes.

"echo x=msgbox ("Your Text Here" ,0, "Your Title Here")>msgbox.vbs"

That will work. I just now did it.

when you type script msgbox.vbs you'll get a message box with an OK button.

i've only used the technique I've described in an emergency where I was in a unique situation. sometimes I use it to create batch file. it's because I use linux a lot and I'm used to the command line.

It's not really practical to write an entire script like that.
I suggest you use the Notepad.exe as described in this fine instructable.

or if you can't get to notepad you can type "edit" at the command prompt and you'll get a text based editor. Well, you will on XP anyway. I don't know about windows 7 for sure.

If you want to now how to program you should google "vbscript fundamentals" you should find the MSDN site for VBScript. Pretty much all you need to know is there.

If you want examples of vbscripts you should google. vbscript examples. you'll get tons of source code. but start with something basic as in simple or easy. at first and work your way up.

I hope this helps.

Let me know if you need anything else.

Christophor



sorry you have to type

c script with no spaces. my spell checker keeps fix it for some reason.

you could click on it to run it if you use the windows interface.

probably you could just type msgbox.vbs and it will run.(after you've created it.)

good luck.
No.
The power is in a person's mind, Notepad is a simple text-editor.

L
I agree with you. Notepad is a simple text editor. Nothing more and nothing less.

I think we can both agree, if you can't code with a simple text editor then you can't really code anyway.

But, let's say simple text editors represent the minimum standard in scripting tools.

What exactly would you say IS an example of "a powerful scripting program?" What makes it more powerful than (insert name of text editor here)?

I'm not being hostile. I really want to know. I use notepad and notepad ++ on a daily basis. They are both simple text editors at heart.

Notepad is great for filtering formatting codes from cut text. Cut from excel. Paste into notepad. Presto! Nice clean text. Cut it from notepad and paste it into whatever like.

I look forward to your reply.

Thanks, Lemonie.

- Chris


 Nice work but do you know how to make it so that if they click "no" it simply opens the message box again?
 yes, and also, there is a much easier way to make a msg box, open notepad, type in: msg * your text here  Voila!! i am not dissing the file in any way, just a suggestion for easier work. 
HandyBob5 years ago
As instructables goes, this is a good one (not counting the typos). Even newbies can understand it.
However hideous the idea, it is possible to program using notepad.

Maybe make a series on this, 'cause this one is a bit too simple.
How about a challenge. Program something using only notepad, an html app maybe? (aah sweet memories)  ;-)
Jack.Miller (author)  HandyBob5 years ago
Aye, just thought I would do a very, very simple one before I move onto some of the harder stuff I do. And typos... I was doing this at night time, so thats why there are -loads-.
Jack
You won't be help responsible, you'll be held responsible.

:p