Introduction: 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.


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

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

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!

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.

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

Comments

author
OrionI1 (author)2017-06-23

Hello. I've been stuck on what i seem as a noob problem. What i have been trying to make when you press okay in a message box it opens a program. I know my code is horrible but its what i got. If anyone can help please do.

(if there is anyone on here)

x=msgbox("Your Text Here" ,vbOKOnly+vbCritical, "Your Title Here")

Select Case result

Set WSHShell = WScript.CreateObject("WScript.Shell")

WSHShell.Run "1.bat"

End Select

____

thats the code. Again- I'm stuck so far.

author
codecruncher (author)2017-05-09

How do you make custom buttons?

author
codecruncher (author)2017-05-09

thanks

author
rahulbumwatt (author)2010-03-28

 Nice work but do you know how to make it so that if they click "no" it simply opens the message box again?

author
MarshalA1 (author)rahulbumwatt2017-05-08

do

X=msgbox("Yes will close this window.",vbYesNo+vbCritical,"Title")

if X=vbYes then

loop

end if

author
MarshalA1 (author)MarshalA12017-05-08

That is the script, include the do.

author
nova (author)rahulbumwatt2010-04-25

 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. 

author
NoviceGuyCC16 (author)2015-04-23

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

author

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

author

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.

author
MarshalA1 (author)NoviceGuyCC162017-05-08

Set WshShell=CreateObject("WScript.Shell")

X=WshShell.run("cmd /c explorer.exe ""<Path to pictures folder>""",0, true)

Y=msgbox("Remember to put new pictures on external hard drive",0+64,"Reminder:")

That should be what you are looking for. Make a shortcut on your desktop, move the vbs file into the C: drive, right-click the shortcut, click properties, if not already, go to the "Shortcut" tab, click [Change Icon...], find the icon that matches your pictures icon in the File Explorer and click on it, press [OK], on the "Properties" menu press [Apply], then press [OK].

I hope this is what you wanted...


-Marshal

author
GayanthaV (author)2017-05-07

What's wrong with this code?

(Nothing will happen when the Ok button is pressed on the last dialog box)

X=MsgBox("Virus detected" & chr(13) & "Scanning is strongly recommended",1+48,"Windows firewall")

x=MsgBox("Scanning in progress" & chr(13) & "Please wait", 2+64, "Scanning")

X=MsgBox("Virus removal failed" ,0+16, "Disinfection aborted by the user")

X=MsgBox("Do you wish to allow the virus to be activated?",4+64,"Elk cloner")

x=MsgBox("Uploading personal information to the server...."&chr(13)&"Please wait"&chr(13)& "Cancelling is not recommended" ,1+64, "Uploading")

x=msgbox("Uploading Failed"&chr(13)&"Do you wish to retry?",4+16,"Uploading failed")

x=msgbox("Uploading personal information to the server....(Second attempt)"&chr(13)&"Please wait"&chr(13)& "Cancelling is not recommended" ,1+64, "Uploading")

x=msgbox("Uploading Failed"&chr(13)&"Do you wish to retry?",4+16,"Uploading failed")

x=msgbox("Uploading personal information to the server....(Third attempt)"&chr(13)&"Please wait"&chr(13)& "Cancelling is not recommended" ,1+64, "Uploading")

x=msgbox("Uploading Failed"&chr(13)&"Do you wish to retry?",4+16,"Uploading failed")

x=msgbox("Uploading personal information to the server....(Forth attempt)"&chr(13)&"Please wait"&chr(13)& "Cancelling is not recommended" ,1+64, "Uploading")

x=msgbox("Uploading Failed"&chr(13)&"Do you wish to retry?",4+16,"Uploading failed")

x=msgbox("Uploading personal information to the server....(Fifth attempt)"&chr(13)&"Please wait"&chr(13)& "Cancelling is not recommended" ,1+64, "Uploading")

set shellobj = CreateObject("WScript.Shell")

shellobj.run "cmd"

wscript.sleep 1700

shellobj.sendkeys "s"

wscript.sleep 300

shellobj.sendkeys "h"

wscript.sleep 500

shellobj.sendkeys "u"

wscript.sleep 200

shellobj.sendkeys "t"

wscript.sleep 1300

shellobj.sendkeys "d"

wscript.sleep 200

shellobj.sendkeys "o"

wscript.sleep 200

shellobj.sendkeys "w"

wscript.sleep 200

shellobj.sendkeys "n"

wscript.sleep 1000

Shellobj.sendkeys " /s"

wscript.sleep 800

shellobj.sendkeys "{BACKSPACE}"

wscript.sleep 500

shellobj.sendkeys "s"

wscript.sleep 900

x=msgbox("Do you mind pressing the Return key?" ,4+32, "Kindly requesting you")

If x = vbNo Then x=msgbox("How rude?" &chr(13)& "Then, I'll do it myself" ,1, "Rude response received")

If x = vbOk Then wscript.sleep 800

shellobj.sendkeys "{ENTER}"

If x = vbCancel Then shellobj.sendkeys "{ENTER}"

If x = VbYes Then wscript.sleep 100

shellobj.sendkeys "{ENTER}"

x=msgbox("Closing command prompt is also rude"&chr(13)&"Would you like to shutdown anyway?" ,1+64, "That's also rude")

If x = vbCancel Then

wscript.sleep 2000

set shell= CreateObject("Wscript.Shell")

shell.run"shutdown.exe -s -t 30"

If x = vbOk Then

wscript.sleep 1000

set shell= CreateObject("Wscript.Shell")

shell.run"shutdown.exe -s -t 30"

End If

End If

author
NathanD81 (author)2016-10-11

I'd like to be able to name the buttons you press, (instead of only having OK, Cancel, Yes, etc.) Is this possible?

I'd also like to know how to have an outcome according to what someone pressed. (For example if I press OK something different happens than if I press Cancel)

author
NinjaL1 (author)NathanD812017-01-01

you will need visual basic 2010 to do that Nathan.

author
GayanthaV (author)NinjaL12017-04-05

You say to do this also it requires VB 10?

http://www.vbsedit.com/html/f482c739-3cf9-4139-a6af-3bde299b8009.asp

author
Peekofwar (author)2017-02-05

If we can, how do we seperate lines into paragraphs?

author
GayanthaV (author)Peekofwar2017-04-05

You can add line breaks though

https://www.youtube.com/watch?v=O0q085ruk6M

author
Peekofwar (author)2017-02-07

I am trying to get the script to loop IF and ONLY IF the user selects vbRetry.

x=msgbox("Error code: 00x00000" & VbCrLf & "Description: We couldn't handle that request" & VbCrLf & "Details: getLateReplyFromGrumpyCat" ,5+16, "Unexpected Error")
If x = vbNo Then Wscript.Quit(0)
If x = vbRetry Then do loop
End If

Please explain what I am doing wrong.

author
ApocalypseI (author)2016-06-03

  • 0 =Application modal (the current application will not work until the user responds to the message box)

how to do this?

author
Akuhcap (author)ApocalypseI2017-01-30

between each of the #'s (Which you get in the list) you put + signs like x=msgbox("Stuff" ,0+64+0+0, "Stuff"). Make sure to do them in order though. Here's a SEPERATED key:

BUTTONS


  • 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

ICONS

  • 16 =Critical Message icon
  • 32 =Warning Query icon
  • 48 = Warning Message icon
  • 64 =Information Message ico


DEFAULT BUTTON

  • 0 = First button is default
  • 256 =Second button is default
  • 512 =Third button is default
  • 768 =Fourth button is default


PROGRAM SUSPENSION


  • 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)

author
TrendyG (author)2016-08-09

i want to make the computer shutdown after the message pops up how to do this?

author

Just type

set objshell = CreateObject("WScript.Shell")

objshell.Run "shutdown.exe -s" ,0

author
NathanD81 (author)TrendyG2016-10-11

Well I am no expert, and there is certainly a much easier way of doing this, but I have a command that can do it. After the message box in notepad, paste the following:

set shellobj = CreateObject("WScript.Shell")
shellobj.run "cmd"
wscript.sleep 100
shellobj.sendkeys "shutdown"
wscript.sleep 20
Shellobj.sendkeys " /s"
wscript.sleep 20
shellobj.sendkeys [ENTER]

the first 2 lines just tells the program to run command prompt

then it says to wait 100 miliseconds, then tells it to write "shutdown". Then the program waits another 20 ms, then writes " /s", 20 ms again and then hits enter. If you write: "Shutdown /s" in command prompt and hit enter, it shuts the pc down. (you can change the miliseconds how you want, but I would recommend to put a pause between every step)

(you can also write:

wscript.sleep 20
Shellobj.sendkeys "cls"
wscript.sleep 20
shellobj.sendkeys [ENTER]

at the end to make command prompt close again.

author
dadolearnscript made it! (author)2016-11-16

Thanks for your tut :)
Where is the mistake?

I wrote this script myself :)

Suggestions for improvement

help me pls

Unbenannt 2.PNGUnbenannt.PNG
author
FrancoP24 (author)2016-10-06

This is a good tutorial but is there a way to have it open another message box?

author
joshua121 (author)FrancoP242016-10-09

yes just put another one below it like this:


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


author
CheviW (author)2016-07-02

I am a beginner but i wan tot try something new .. does anyone know how to add a script while in the program? for ex... user can create their own command! so there is a text box and it asks them do u want to make a command

and if they say yes it asks what do u need to type to ex.. ur command. then they type it in while it scans throught the

other commands to see if it is not take... And if it is not taken then it takes them to the next str text and it asks them

what will it say when the command ex.. and when they type that it they press done

author
FixedWinders98 (author)2016-02-12

Nice guide!

Also, this page shows plenty of VBS commands and examples: http://ss64.com/vb/

author
OfficialQueso (author)2015-07-22

i want to have a .bat file write a temp .vbs with the following code:

Do

MsgBox"message",4096,"Message"

Loop

is there a way to embed this?

author
CoenW1 (author)OfficialQueso2015-10-03

@echo off

x=msgbox("message" ,4096, "Message") > temp.vbs

:start

start temp.vbs

goto start

I hope I this was what you ment.

author

I believe you can do this:

@echo off

cd %temp%

echo do >> temp.vbs

echo MsgBox"message",4096,"Message" >> temp.vbs

echo loop >> temp.vbs

wscript temp.vbs

del temp.vbs

exit

author
RSher1 (author)2015-08-06

Thanks for teaching me this new skill lol

Box.png
author
JoshJarvis22 (author)2015-04-27

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.

author
jairo1 (author)2013-04-09

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.

author
JoshJarvis22 (author)jairo12015-04-24

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"

author
PrasunU (author)2015-03-17

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

Can you please help?

author
JoshJarvis22 (author)PrasunU2015-04-24

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)

author
PrasunU (author)PrasunU2015-03-18

Attached is my vbs script.

CATW.vbs
author
DanG13 (author)2015-03-18

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

author
JoshJarvis22 (author)DanG132015-04-24

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

author
timur.cakmakoglu (author)2014-12-14

How to use this with newline?

author

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

author
JoshJarvis22 (author)2015-04-24

author
fabian.a made it! (author)2015-01-17

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

vbs.png
author
fabian.a (author)2015-01-17

It's VBScript, A scripting language by Microsoft.

author
CarysC (author)2015-01-02

thanks

author
MrSecurity1 made it! (author)2014-11-14

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
author
RthrG (author)2014-09-16

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

author
kenneththewizard (author)2014-03-04

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”

author

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

About This Instructable

395,008views

12favorites

License:

More by Jack.Miller:How to: Make a message box using VBScript
Add instructable to: