Custom action before MSI uninstallation with Wix

2019-02-15 08:02发布

I'm using Wix to code my own MSI installer. I need to run the custom action only before uninstallation of the product, but before any registry values or files are removed. I did the following (just to try):

<Property Id='CALC'>Calc.exe</Property>
<CustomAction Id='BeforeUninstall01' Property='CALC' ExeCommand='' Return='check' />

<InstallExecuteSequence>
  <Custom Action='BeforeUninstall01' After='InstallInitialize'>Installed</Custom>
</InstallExecuteSequence>

It works if I choose to uninstall from the Control Panel, but if I run my MSI instead (while it's already installed) the BeforeUninstall01 custom action is triggered anyway, which it shouldn't.

Any idea how to change this condition?

2条回答
看我几分像从前
2楼-- · 2019-02-15 08:10

try an additional condition to check that the product is not being upgraded

<Custom Action='BeforeUninstall01' After='InstallInitialize'>Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
查看更多
家丑人穷心不美
3楼-- · 2019-02-15 08:13

You choose the condition "Installed".

Given your code the wanted condition using the built-in property "REMOVE" will result in:

<InstallExecuteSequence>
   <Custom Action='BeforeUninstall01' After='InstallInitialize'>REMOVE="ALL"</Custom>
</InstallExecuteSequence>

This also allows you (even if it is not necessary) to uninstall a single feature, but not the whole product without that your custom action (ca) is triggered. In other words, the ca is triggered always and only, if

Yours condition starts the ca always, but not for first install (incl. repair, update, uninstall, modify, patch, etc. This is not, what you need, indeed.

The condition of Reubz is slightly different, this would start always but not for first install and not during a Major Upgrade, which is not a real improvement here.

Concerning sequencing: If your ca really needs elevated rights then you have to run the custom action "deferred" with system rights and change your given ca definition to (if not, let it):

<CustomAction Id='BeforeUninstall01' Property='CALC' ExeCommand='' Execute="deferred" Impersonate="no" Return="check" />

(I am not a WiX wizard, only I know MSI quite well, so I have not checked any part of your WiX code, only the issues.)

查看更多
登录 后发表回答