Visual c++ 如何获取VC+的正确返回值/状态+;2005年在国家统计局

Visual c++ 如何获取VC+的正确返回值/状态+;2005年在国家统计局,visual-c++,nsis,visual-c++-2005,Visual C++,Nsis,Visual C++ 2005,我想用NSIS静默安装 但是,不会返回正确的退出代码。我测试了几种类型的变体。我想到的最好的办法是: DetailPrint "Installing VC++ 2005" File "${STOCKINPUTFOLDER}\bin\Debug\vcredist_x86.EXE" ClearErrors ExecWait "$OUTDIR\vcredist_x86.EXE /q:a /c:$\"msiexec /i vcredist.msi /qb /norestart$\

我想用NSIS静默安装

但是,不会返回正确的退出代码。我测试了几种类型的变体。我想到的最好的办法是:

DetailPrint "Installing VC++ 2005"
    File "${STOCKINPUTFOLDER}\bin\Debug\vcredist_x86.EXE"
    ClearErrors
    ExecWait "$OUTDIR\vcredist_x86.EXE /q:a /c:$\"msiexec /i vcredist.msi /qb /norestart$\"" $0 ; also can use /qn 

    ;do not delete the file out-rightly so that evaluation of IfErrors below is clean           
    IfErrors execError noError

    execError:
        Goto ShortEndInstall

    ShortEndInstall:
        MessageBox MB_OK|MB_ICONEXCLAMATION "ShortEndInstall"
        Delete "$OUTDIR\vcredist_x86.EXE" ;we did not delete the file outrightly so that evaluation of IfErrors is clean
        Quit

    noError:
        ${If} $0 != 0
            MessageBox MB_OK|MB_ICONEXCLAMATION "You did not complete the installation of the VC++ 2005 re-distributable. Installation will now abort. Return code $0"
            Goto ShortEndInstall
        ${EndIf}

        MessageBox MB_OK|MB_ICONEXCLAMATION "No error"
        Delete "$OUTDIR\vcredist_x86.EXE" ;we did not delete the file outrightly so that evaluation of IfErrors is clean
但是,当我故意点击VC++2005安装的“取消”按钮时,NSIS仍然认为它是成功的安装(我在指令
消息框MB|u OK | MB|u图标下的对话框“无错误”

我如何准确、正确地获取返回的错误(例如,当我自己“取消”安装时)

编辑:

在@Anders的帮助下,我现在有了以下内容,但仍然失败(即在VC++2005安装完成时,
未安装
。我还尝试了VC++2005安装的不同命令行选项)


可能vcredist_x86.exe没有从MsiExec正确返回退出代码

如果
ExecWait
能够找到并启动进程(
IfErrors
为“false”),则NSIS将保证从子进程返回正确的退出代码

$0!=0
实际上是一个字符串比较,您应该使用
$0 0
来比较32位数字,但这不是本例中的问题

!include LogicLib.nsh
Section

ExecWait '"cmd" /c exit 0' $0
${If} ${Errors}
${OrIf} $0 <> 0
    Abort "Error, child process exited with $0" # Will not abort here
${EndIf}

ExecWait '"cmd" /c exit 1234' $0
${If} ${Errors}
${OrIf} $0 <> 0
    Abort "Error, child process exited with $0" # Will abort here
${EndIf}

SectionEnd 
!包括LogicLib.nsh
部分
ExecWait'cmd”/c退出0'$0
${If}${Errors}
${OrIf}$0
Abort“错误,子进程已退出$0”#此处不会中止
${EndIf}
ExecWait'cmd”/c退出1234'$0
${If}${Errors}
${OrIf}$0
Abort“错误,子进程已退出$0”#将在此处中止
${EndIf}
分段结束

ExecWait之后的$0是多少?0或其他数字?@Anders总是
0
那么如何确保
vcredit_x86.exe
MsiExec
正确返回退出代码?(我听说过%ERRORLEVEL%,但不知道如何在这里正确应用它)注意:运行
vcredit_x86.EXE/q:a/c:“msiexec/I vcredit.msi/qb/norestart”
直接从命令行检查
%ERRORLEVEL%
,即使在取消安装后仍然返回
0
最坏情况,检查它是否在执行后安装:但您应该首先尝试查找一些命令行选项文档…感谢@Anders提供您在上面共享的链接。那么,这是否意味着我可以在静默安装后简单地执行
System::Call'MSI::MsiQueryProductState(t“${msvcredit\u PRODUCTCODE}”)I.r0'
,以了解安装是否成功?请记住,如果有SP1或SP1+更新,则GUID不同,请参阅
!include LogicLib.nsh
Section

ExecWait '"cmd" /c exit 0' $0
${If} ${Errors}
${OrIf} $0 <> 0
    Abort "Error, child process exited with $0" # Will not abort here
${EndIf}

ExecWait '"cmd" /c exit 1234' $0
${If} ${Errors}
${OrIf} $0 <> 0
    Abort "Error, child process exited with $0" # Will abort here
${EndIf}

SectionEnd