How to cancel vb script msgbox

How To: Make a Message Box Using VBScript

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

19 People Made This Project!

Did you make this project? Share it with us!

Recommendations

  • Toys & Games Contest

  • Big vs Small Challenge

  • Fix It Challenge

69 Comments

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.

Hello you could substitute numbers for the vb constants. Like this

Dim Ansx, BMsg
BMsg = "This is a script to try options on a message box"
Ansx = Msgbox (BMsg, 5 + 16, "This is a prompt")
If Ansx = 6 then
Msgbox "You selected YES!", 0, "This is your answer"
Elseif Ansx = 4 then
Msgbox "You selected Retry!", 0, "This is your answer"
else
Msgbox "You selected NO!", 0, "This is your answer"
END if

Try This Code:

do
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 End if
End If
Loop

Forgot the first end If

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

Pls Help !!

Learn The IE Custom Buttons And Custom Logo Tutorial From This Website www.tutorialbook.com/Use-IE-CUSTOM-BUTTON-ICON-VBS.html

Hello! i have a question: is it possible to run batch commands like "start cmd.exe", or "echo", if "ok button is pressed?

thanks

can i make it so an answer they give opens a file or a tab in a web browser?

Hm......................................

How would you make it so that it detects if a user says no or yes. i want it to close the vbs if the user says no. and continue if the user says yes. how would i do that?

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

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) & "Canceling 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) & "Canceling 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) & "Canceling 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) & "Canceling 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) & "Canceling 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

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?

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.

How do you make custom buttons?

thanks

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

do

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

if X = vbYes then

loop

end if

That is the script, include the do.

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.