将vbYesNoCancel的输出传递给批处理

时间:2014-02-05 10:16:43

标签: batch-file vbscript

美好的一天,我正在为一个简单的程序编写一个批处理文件,我正在使用VBscript来接收用户的输入。在程序的这一点上,我有一个问题:“你想现在备份吗?”在一个MsgBox中。如果用户按下yes,则必须转到批处理中的标记:AUTOBACKUP。否则,它必须转到:REJECTAB。这是我目前的代码,但它不起作用?我怎么能纠正它?

 :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

提前致谢。

1 个答案:

答案 0 :(得分:2)

@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%

对于一个简单的MsgBox,最好使用WScript.Quit作为错误级别返回MsgBox函数的结果