installationinstallshieldwindows-installerinstallshield-2014

How to run custom actions while running the MSI installer in silent mode


I've created an MSI installer using Installshield 2014. While running it from UI everything works fine but when I run it in silent mode using below command then my custom actions are not firing at all:

C:\>msiexec /i "myApplication.msi" /qn WEBURL=http://localhost/mywebapp /log  out.txt

WEBURL is the property required by the custom action. Value of WEBURL is passed to C# class library method as an argument. The C# method is called by my custom action which gets called when I click on Install button on begin installation wizard step. My custom action gets executed always i.e. I've kept the condition for the execution of the custom action as 1 which means it executes under all circumstances.

In the log file I also see the value of WEBURL property getting correctly set. I'm not able to get as to what is stopping my custom action to fire while running the installer in silent mode?

Update: As suggested by Michael, after putting the custom action in InstallExecuteSequence it starts getting executed in silent mode. But now the problem is that it starts getting executed twice in UI mode as the same action was already getting executed through a button click on one of the dialogs which appears during InstallUISequence. So I want to execute my custom action by putting it into InstallExecuteSequence only when I'm running the installer in silent mode (so that it executes only once if I'm in UI mode).


Solution

  • When you run with /qn, the wizard is not shown. Even the entire InstallUISequence is skipped. So if you want your action to always run, you should not invoke it only from a button click. When the button isn't shown, it cannot be clicked.

    Instead find a spot in the InstallExecuteSequence to schedule it. (If you have no other requirements, you probably still want to schedule it sometime after CostFinalize to mirror the non-silent case.) This scheduling will run the action whether or not you have UI.

    However, it also runs it whether you are installing or uninstalling, so either alter your condition or your action to take that into account. The simplest approach may check whether the Installed property is set; a more robust check may verify the install and action states of a relevant component. The latter can be necessary if you need to conditionally do something in maintenance scenarios that add or remove a feature.

    Since you mention you also need it to run during the UI, you have to take extra steps. You may be able to set the msidbCustomActionTypeFirstSequence scheduling option as shown below.

    enter image description here

    Or you may have to detect the scenario, for example by checking UILevel, or by setting and checking your own property when your action runs. You may also need to split it into multiple entry points so you can tell UI from immediate Execute; there does not appear to be a RunMode that distinguishes the two. (Am I forgetting a property that gets set?)