Passing vbYesNoCancel output to batch
Hello, I am about to write a batch file for a simple program and I am using VBscript to get input from users. At this point in the program, I have a question: "Do you want to make a backup now?" in MsgBox. If the user clicks yes, they should navigate to the tag in the package: AUTOBACKUP. No, it should go: REJECTAB. Here is the code I have but it doesn't work? How can I fix it?
:STARTUPDAS
ECHO Wscript.echo i=msgbox("The automatic backup function is active. Would you like to backup now?", VBYesNoCancel + VBQuestion, "BACKUP")>vbst.vbs&vbst.vbs
SET _stringb
ENDLOCAL & SET i=%_stringb%
cls
cls
echo.
echo.
echo The automatic backup function is active.
echo Would you like to perform a backup now? Y/N
echo.
if i==6 goto AUTOBACKUP
if i==7 goto REJECTAB
echo.
echo Invalid option. Please try again
echo.
pause
:STARTUPDAS
ECHO Wscript.echo i=msgbox("The automatic backup function is active. Would you like to backup now?", VBYesNoCancel + VBQuestion, "BACKUP")>vbst.vbs&vbst.vbs
SET _stringb
ENDLOCAL & SET i=%_stringb%
cls
cls
echo.
echo.
echo The automatic backup function is active.
echo Would you like to perform a backup now? Y/N
echo.
if i==6 goto AUTOBACKUP
if i==7 goto REJECTAB
echo.
echo Invalid option. Please try again
echo.
pause
Thanks in advance.
0
source to share
1 answer
@echo off
call :MsgBox "Should i do something?" "VBYesNoCancel+VBQuestion" "Just asking"
if errorlevel 7 (
echo NO - do nothing
) else if errorlevel 6 (
echo YES - do something
) else if errorlevel 2 (
echo CANCEL - do .....
)
exit /b
:MsgBox prompt type title
setlocal enableextensions
set "tempFile=%temp%\%~nx0.%random%%random%%random%vbs.tmp"
>"%tempFile%" echo(WScript.Quit msgBox("%~1",%~2,"%~3") & cscript //nologo //e:vbscript "%tempFile%"
set "exitCode=%errorlevel%" & del "%tempFile%" >nul 2>nul
endlocal & exit /b %exitCode%
For a simple MsgBox, it is better to use WScript.Quit
to return the result of the MsgBox function as the error level
+2
source to share