繁体   English   中英

使用Wix在MSI中自定义操作出错时显示最终用户消息

[英]Display end-user message in case of an error in custom action in MSI with Wix

说,我有以下WIX标记,指示MSI安装程序从包含的DLL调用自定义操作:

<CustomAction Id="CA_SetProperties_Finalize" 
        Property="CA_OnInstallFinalize" 
           Value="[Installed],[REINSTALL],[UPGRADINGPRODUCTCODE],[REMOVE]" />

<CustomAction Id='CA_OnInstallFinalize' 
       BinaryKey='CADll' 
        DllEntry='msiOnInstallFinalize' 
         Execute='deferred' Impersonate='no' />

<InstallExecuteSequence>
  <Custom Action='CA_SetProperties_Finalize' 
          Before='InstallFinalize'></Custom>
  <Custom Action='CA_OnInstallFinalize' 
           After='CA_SetProperties_Finalize'></Custom>
</InstallExecuteSequence>

<Binary Id='CADll' SourceFile='Sources\ca-installer.dll' />

DLL本身具有以下用于自定义操作的C ++代码:

#pragma comment(linker, "/EXPORT:msiOnInstallFinalize=_msiOnInstallFinalize@4")

extern "C" UINT __stdcall msiOnInstallFinalize(MSIHANDLE hInstall) 
{
    //Do the work
    if(doWork(hInstall) == FALSE)
    {
        //Error, cannot continue!
        return ERROR_INSTALL_FAILURE;
    }

    return ERROR_SUCCESS;
}

当我的doWork方法失败时,安装不应该继续,所以我返回ERROR_INSTALL_FAILURE 问题是,在这种情况下,安装程序只是退出,安装GUI窗口就会消失。

所以我很好奇,有没有办法更改Wix标记,以便能够显示用户消息,以防我的自定义操作返回错误?

我使用它来创建消息框来处理我的DLL中的错误:

PMSIHANDLE hRecord = MsiCreateRecord(0);
MsiRecordSetString(hRecord, 0, TEXT("Enter the text for the error!"));
MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord);
return ERROR_INSTALL_USEREXIT;

我能够将该代码转换为VB.NET并在自定义操作中使用它来显示Error上的弹出窗口

.Net代码看起来有很大不同

Private Shared Sub DisplayMSIError(session As Session, msg As String)
  Dim r As New WindowsInstaller.Record(0)
  r.SetString(0, msg)
  session.Message(InstallMessage.Error, r)
End Sub

我也在MSDN上发现它使用vbscript http://msdn.microsoft.com/en-us/library/xc8bz3y5(v=vs.80).aspx

对于C#用户......

                string msg = "XXXXXX code is invalid";
                Record r = new Microsoft.Deployment.WindowsInstaller.Record(0);
                r.SetString(0, msg);
                session.Message(InstallMessage.Error, r);
                session.Log(msg);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM