Video Screencast Help
Search Video Help Close Back
to help
Not able to make it to Vision this year? Get a sampling in the Best of Vision on Demand group.

MSGBOX with Yes No buttons that return an exit code.

Updated: 17 Jun 2010
stevericks's picture
+1 1 Vote
Login to vote

I had been tasked with rolling out XP SP3. The actual install was easy enough, but I had to come up with a message box at the start that gave them the option to say No to running it now.
The problem was that with my very basic knowledge of vbscript I could only create a msgbox that no matter what button I pressed, it reported back a 0 to say it had run properly.

After a few hours googling, I found this script which output a code of 100 for Yes and 200 for No.

So I just thought I would share it with everyone...

Dim objShell, intReturn
Set objShell = CreateObject("Wscript.Shell")

intReturn = objShell.Popup("Do you see this ""Hello World""?",4,"Hello World", 4+32)
If intReturn = 6 Then
 MsgBox "yes, exit code 100"
 WScript.Quit(100)
Else
 MsgBox "no, exit code 200"
 WScript.Quit(200)
End If