2

I've got a CMD file that writes a MsgBox popup command to a VBScript file, then turns around and immediately executes it. Originally it just used an "OK" button to dismiss the warning that user version was out of date. I want to modify it to use the Yes/No/Cancel buttons to allow user automatic version update.

Here is the code that just causes the pop-up. I've tried a few different things to try to get the .vbs file to return a value, but am having issues getting the syntax right. Any suggestions?

@echo X=MsgBox("Your Version: %VER%" +vbCrLf+ "Recommended: %RVER%" +vbCrLf+ "Do you want to update the version?",vbYesNoCancel,"Warning Message"^) >%APPDATA%\temp_msg2.vbs

call %APPDATA%\temp_msg2.vbs

Thanks!

Mark Seagoe
  • 480
  • 8
  • 15

2 Answers2

3

VBScript is just a language, with many different hosts and applications - not just shell-scripting, so setting the return-value of a script is the responsibility of the host, not the language. In this case the host is either cscript or wscript (for command-line and windowed hosts, respectively). Both hosts expose the WScript object which is where you specify the return code as an argument to the Quit method (note that VBScript doesn't use parenthesis on void (Sub) method calls:

WScript.Quit 123 

If you want to return the value from MsgBox you can provide it directly:

WScript.Quit MsgBox( "Foobar" )

Your .cmd batch file will need to know the numeric value of vbYes, vbNo, and vbCancel.

...I suggest doing all of the scripting from within the VBScript file and avoiding the use of .cmd/.bat files completely, if you can, as VBScript is much more readable and powerful (though I prefer using the JScript language instead, but that's just me).

MSDN has a reference to all of the members of the WScript object: https://msdn.microsoft.com/en-us/library/at5ydy31(v%3Dvs.84).aspx

Here's a page listing other objects and functionality available from within wscript/cscript (collectively: "Windows Script Host"): https://msdn.microsoft.com/en-us/library/98591fh7(v=vs.84).aspx

Dai
  • 141,631
  • 28
  • 261
  • 374
2
@ECHO OFF
SETLOCAL
echo X=MsgBox("Your Version: %VER%" +vbCrLf+ "Recommended: %RVER%" +vbCrLf+ "Do you want to update the version?",vbYesNoCancel,"Warning Message"^) >U:\temp_msg2.vbs
>>U:\temp_msg2.vbs echo wscript.quit X

call u:\temp_msg2.vbs

ECHO %errorlevel%

GOTO :EOF

Showed 6 for Yes, 7 for No and 2 for Cancel/big red x for me.

Magoo
  • 77,302
  • 8
  • 62
  • 84