WindowsInstaller取消安装

时间:2017-10-25 13:41:00

标签: c# windows-installer

我正在安装带有Microsoft.Deployment.WindowsInstaller.Installer对象的MSI包,并希望能够取消安装。据我所知,这可以通过SetExternalUI方法完成。但它似乎不起作用。回调只被调用一次......

这是我的代码:

internal class WinInstallerExecutor : ExecutorAbstract
{
    public override ProcessingResultEnum Run()
    {

        try
        {
            Installer.SetInternalUI(InstallUIOptions.Silent);
            Installer.SetExternalUI(UiHandler, InstallLogModes.Verbose);
            Installer.InstallProduct(@"C:\Path\to\Package, "params");
            return ProcessingResultEnum.ExecutionSuccesful;
        }
        catch (Exception ex)
        {
            return ProcessingResultEnum.ExecutionNotSuccessful;
        }
    }

    private MessageResult UiHandler(InstallMessage messageType, string message, MessageButtons buttons, MessageIcon icon,
        MessageDefaultButton defaultButton)
    {
        return _abort ? MessageResult.Cancel : MessageResult.None;
    }
}

这是正确的方法吗?

1 个答案:

答案 0 :(得分:1)

得到了...... 正如我发现here消息过滤器是问题。有了这条线:

Installer.SetExternalUI(UiHanlder,
                InstallLogModes.Verbose | InstallLogModes.ActionData | InstallLogModes.ActionStart |
                InstallLogModes.CommonData | InstallLogModes.Error | InstallLogModes.ExtraDebug |
                InstallLogModes.FatalExit | InstallLogModes.FilesInUse | InstallLogModes.Info |
                InstallLogModes.Initialize | InstallLogModes.LogOnlyOnError);

回调引发了更多。如果从回调中返回MessageResult.Cancel,安装将取消。