Search code examples
c#custom-actionwix3.5

Disable Wix Custom action on /quiet /silent


In a WIX custom action, is there a way to detect whether the MSI was invoked with /silent or /quiet command line switches? Basically what I want is to not execute the custom action (since it shows a form) or handle it differently if these command line switches were passed but I am unable to find this out.

Is there a way to possibly detect it?


Solution

  • I finally figured it out. Wix basically always sets the UILevel property to 2.0. It has its own property called WixBundleUILevel. Now important thing here is that prior to Wix 3.11 this WixBundleUILevel was an internal property and was not accessible to Bundle projects or MSI Custom Actions. So here is what I did

    1. Defined a property in MSI called UI_LEVEL (important, make it all upper case)
    2. In Bundle.wxs, right where I call MSIPackage, I set the UI_LEVEL property like so

      <MsiPackage SourceFile="$(var.MsiPath)"> <MsiProperty Name="UI_LEVEL" Value="[WixBundleUILevel]" /> </MsiPackage>

    Then finally in the custom action I check for this property like

    int uiLevel;
                    if (int.TryParse(session["UI_LEVEL"], out uiLevel))
                    {
                        if (uiLevel == 4)
                            using (var form = new WhatsNew())
                            {
                                form.ShowDialog();
                            }
                        else
                            session.Log("Skipping What's new dialogue as UI Level is not 4");
    
                    }
                    else
                    {
                        session.Log("Couldnt figure out the UI level, so skipped the prompt");
                    }
    

    And finally

    here are the possible values of this f**ed up property
                    WixBundleUILevel              Value     Burn parameters
                    BOOTSTRAPPER_DISPLAY_FULL       4         (none)
                    BOOTSTRAPPER_DISPLAY_PASSIVE    3         /silent
                    BOOTSTRAPPER_DISPLAY_NONE       2         /quiet