wixwindows-installerwix3.9

Wix Installer Registry Key Always Returns 1


Good afternoon, I am trying to check for a specific registry key. If the key exists, I want to display a message that the application needs to be removed prior to continuing with the installation. If the key doesn't exist, installation should continue. I know about Upgrade elements and such, but in this case it is not applicable due to the company's structure . This is what I currently have:

<Product Id="B93715AA-AB42-426D-B47E-5F0370BBA259" Name="MyApp" Language="1033" 
       Version="20.2.0.0" Manufacturer="MyCompany" UpgradeCode="c2d873b4-6160-4d6a-91b7-9cb7193bbddf" >

<Package InstallerVersion="500" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Property Id="ARPSYSTEMCOMPONENT" Value="1" />

<Property Id="TESTPROPERTY" Secure="yes" Value="0">
  <RegistrySearch Id="MyTestProperty" 
                  Root="HKLM" 
                  Key="Software\MyCompany\MyApp" 
                  Name="InstallPath" 
                  Type="raw" 
                  Win64="no" />
</Property>

<Condition Message="You must uninstall MyApp first before running this installer.">
  <![CDATA[TESTPROPERTY<>0]]>
</Condition>
</Product>

I've tried other things like , 0]]>, etc. to no avail. The msi log shows the property is set to 1. My understanding is that, if the key exists, the property is set to 1, otherwise it is not set. Whatever I set the condition's check to be, the message either always shows up, or never shows up (whether the registry key exists or not).

Any help with resolving this will be greatly appreciated. I should note that, since Friday, I've read many articles on this site and others, and the answers there have not helped. I tried following the example of checking for the .Net Framework, but that didn't work for me. I should also say that my experience with Windows Installer technology is very limited.


Solution

  • Try this:

    <Property Id="TESTPROPERTY" Secure="yes">
      <RegistrySearch Id="MyTestProperty" 
                      Root="HKLM" 
                      Key="Software\MyCompany\MyApp" 
                      Name="InstallPath" 
                      Type="raw" 
                      Win64="no" />
    </Property>
    
    <Condition Message="You must uninstall MyApp first before running this installer.">
      <![CDATA[Installed OR NOT TESTPROPERTY]]>
    </Condition>
    

    Remove the explicit setting of value on the property, and test for empty or not. I added the INSTALLED property as well, which will not perform the check if the application is already installed. You may or may not want to keep that.