How to check for installed package in WiX 3.0?

2019-03-30 03:33发布

问题:

I'd like to check that Crystal Reports Basic for Visual Studio 2008 is installed as a condition for my own installation package.

I found this in the bootstrapper description for this product (C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5\product.xml) :

<InstallChecks>
  <MsiProductCheck Property="CRVSInstalled" Product="{AA467959-A1D6-4F45-90CD-11DC57733F32}"/>
  <MsiProductCheck Property="CRVSRunTimex86Installed" Product="{CE26F10F-C80F-4377-908B-1B7882AE2CE3}"/>
  <MsiProductCheck Property="CRVSRunTimex64Installed" Product="{2BFA9B05-7418-4EDE-A6FC-620427BAAAA3}. "/>
</InstallChecks>

Trying to mimic this behavior in WiX, I did the following :

<Property Id="CRVSINSTALLED">
  <ComponentSearch Id="CRVSInstalledSearch" Guid="{AA467959-A1D6-4F45-90CD-11DC57733F32}" />
</Property>
<Property Id="CRVSRUNTIMEX86INSTALLED">
  <ComponentSearch Id="CRVSRunTimex86InstalledSearch" Guid="{CE26F10F-C80F-4377-908B-1B7882AE2CE3}" />
</Property>
<Property Id="CRVSRUNTIMEX64INSTALLED">
  <ComponentSearch Id="CRVSRunTimex64InstalledSearch" Guid="{2BFA9B05-7418-4EDE-A6FC-620427BAAAA3}" />
</Property>
<Condition Message="!(loc.CrystalReportsRequired)">Installed OR CRVSINSTALLED OR CRVSRUNTIMEX86INSTALLED OR CRVSRUNTIMEX64INSTALLED</Condition>

But it seems that ComponentSearch is looking for package components (files, directories) that have their own ids, rather than looking for the package itself.

So how can I do this ?

回答1:

As suggested here :

Try a registry search under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{productcode}. Also consider a search under HKCU if both your product and the dependency are per-user products.

This goes like this :

<Property Id="CRVSINSTALLED">
  <RegistrySearch Id="CRVSInstalledSearch" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\{AA467959-A1D6-4F45-90CD-11DC57733F32}" Name="InstallDate" Type="raw" />
</Property>
<Property Id="CRVSRUNTIMEINSTALLED">
  <RegistrySearch Id="CRVSRunTimeInstalledSearch" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\{CE26F10F-C80F-4377-908B-1B7882AE2CE3}" Name="InstallDate" Type="raw" />
</Property>
<Property Id="CRVSRUNTIMEINSTALLED">
  <RegistrySearch Id="CRVSRunTimeInstalledSearch" Root="HKLM" Key="Software\Microsoft\Windows\CurrentVersion\Uninstall\{2BFA9B05-7418-4EDE-A6FC-620427BAAAA3}" Name="InstallDate" Type="raw" />
</Property>


回答2:

You can use Upgrade table

<Upgrade Id="36E76465-5548-390F-955A-2776582C6A6C">
  <UpgradeVersion OnlyDetect="yes" Property="TFSCLIENT" Minimum="11.0.50727" />
</Upgrade>
<Condition Message="ERROR: Team Explorer for Microsoft Visual Studio 2012 is not installed">
  Installed OR TFSCLIENT
</Condition>

Now the tricky bit is to find Upgrade Code (specified in Id attribute above). If you have an MSI package, just look at it by Orca. If you don't - try this solution.



回答3:

The windows installer API has the MsiQueryProductState function in msi.dll to do this. Unfortunately you'll have to write a custom action to make use of this in your installer. The assemblies in C:\Program Files\Windows Installer XML v3\SDK may make this easier.



标签: wix wix3