How To: Make a Message Box Using VBScript

464,132

13

63

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

9 People Made This Project!

Recommendations

  • Arduino Contest 2019

    Arduino Contest 2019
  • Trash to Treasure

    Trash to Treasure
  • Tape Contest

    Tape Contest

63 Discussions

0
None
Peekofwar

2 years ago

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.

1 reply
1
None
ВладV

10 months ago on Step 5

You can use MSGBox instead, MSGbox "Sample Text", 64, "Title"

0
None
EthanW64

Question 11 months ago

Is there a way that I can make the In-Message icon a custom icon? like a .png, for ex.???

Pls Help!!

0
None
GayanthaV

1 year ago

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

1 reply
0
None
Steve2018_GamingGayanthaV

Reply 1 year ago

Son of a **** xD Dude it works. I was scared when cmd start typing shutdown commands but in my good luck i knew the secret command to abort this. Shutdown -a xD It works so why you say it didn't work? To make us feel bad when try it?

0
None
OrionI1

1 year ago

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.

0
None
codecruncher

1 year ago

How do you make custom buttons?

0
None
rahulbumwatt

9 years ago on Step 3

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

3 replies
0
None
MarshalA1rahulbumwatt

Reply 1 year ago

do

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

if X=vbYes then

loop

end if

0
None
novarahulbumwatt

Reply 8 years ago on Introduction

 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. 

0
None

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

3 replies

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.

0
None
MarshalA1NoviceGuyCC16

Reply 1 year ago

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

0
None
NathanD81

2 years ago

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)

2 replies
0
None
NinjaL1NathanD81

Reply 2 years ago

you will need visual basic 2010 to do that Nathan.

0
None
GayanthaVNinjaL1

Reply 2 years ago

You say to do this also it requires VB 10?

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