Marco Rebsamen
Marco Rebsamen

Reputation: 605

WindowsInstaller Cancel Installation

I'm installing a MSI Package with the Microsoft.Deployment.WindowsInstaller.Installer Object and want the ability to Cancel the Installation. As far as I could find out this can be done by the SetExternalUI method. But it doesn't seem to work. The callback is only called once...

This is my Code:

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;
    }
}

Is it right approach at all?

Upvotes: 0

Views: 166

Answers (1)

Marco Rebsamen
Marco Rebsamen

Reputation: 605

Got it... As I've found out here the message filter was the problem. With this line:

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);

the callback fires a lot more. And if MessageResult.Cancel is returned from the callback, the installation cancels.

Upvotes: 1

Related Questions