Wix uninstall product using command line during installation

蓝咒 提交于 2019-12-11 11:50:01

问题


I made a Wix project that attemps to install a simple .txt example file. But, as a prerequisite, I want to uninstall a previous application.

To do so, I know msiexec allows you to uninstall a product by simply writing:

msiexec /x {PRODUCT_CODE}

on a command line.

Fortunately, I know this PRODUCT_CODE, so I tried to create a CustomAction to uninstall that product before the installation starts, like this:

<CustomAction Id="PropertyAssign" Property="SilentLaunch" Value="msiexec.exe /x {EA29682C-7DA1-441C-BF3E-702491F59258}" Execute="immediate" />
<CustomAction Id="SilentLaunch" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no" />

<InstallUISequence>
  <Custom Action="PropertyAssign" After="CostFinalize" />
  <Custom Action="SilentLaunch" After="PropertyAssign" />
</InstallUISequence>

But when I run the .msi, it says there was an unexpected error with code 2762 and exits installation.

I know the mistake is in that line, as if I erase it, everything goes ok.

Any idea on how to run that command line without any mistakes?


回答1:


The UI sequence should never make changes to the state of the machine. It should only gather, validate and report data to the user. All changes must be made in the execute sequence.

There is a mutex in Windows / MSI ( _MSIExecute ) that enforces one execute sequence per machine. Therefore you cannot call msiexec from an MSI. But what you can do is author a Major Upgrade rule to detect the other product and remove it. The Windows Installer standard action RemoveExisitingProducts can uninstall any MSI not just previous versions of yourself.



来源:https://stackoverflow.com/questions/19025798/wix-uninstall-product-using-command-line-during-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!