0

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.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
Bianchi
  • 3
  • 2
  • Can you explain why you think an Upgrade element can't be used? – Christopher Painter Apr 06 '15 at 20:49
  • @ChristopherPainter - It's weird. The team I'm in, creates the msi for major releases. Any patches or service packs are created by a different team. We won't have any knowledge of these patches so, when we uninstall the app, or install a new major upgrade, we need to check for the registry key to see if our app has been patched and notify the user. Like I said, it's weird, but that's how this company functions; no chance of changing that. – Bianchi Apr 06 '15 at 21:01

2 Answers2

0

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.

Ryan J
  • 8,275
  • 3
  • 25
  • 28
  • Thanks for your answer, but that didn't work either. I still get the message whether the key exists in the registry or not. – Bianchi Apr 06 '15 at 20:45
  • @Bianchi give this suggestion another go. If it still doesn't work, maybe paste the log and (if you can) the registry key value currently in your registry. – Ryan J Apr 06 '15 at 21:23
  • The Installed property is case-sensitive and you've spelt it wrong. You've also got the logic the wrong way around. The install will proceed if the properties resolve to be true in the condition, so your condition should be Installed or TESTPROPERTY so it will continue if TESTPROPERTY is set or the product is already installed. – PhilDW Apr 07 '15 at 17:55
  • @PhilDW Mistake on the typo, but the OP wishes to have the installation continue if the registry key is _not_ found, meaning the property should NOT be set. – Ryan J Apr 07 '15 at 18:24
  • So this ended up working after I rebooted my machine. Not sure why though. Thanks to all for your help. – Bianchi Apr 07 '15 at 18:29
0

I'm not sure where you read that RegistrySearch returns a 1 if a key exists. I've never heard of that. According to the msdn doco it:

Name

The registry value name. If this value is null, then the value from the key's unnamed or default value, if any, is retrieved.

...

Note that it is not possible to use the RegLocator table to check only for the presence of the key. However, you can search for the default value of a key and retrieve its value if it is not empty.

It's hard to say without seeing the MSI or log but I'm guessing you have the property defined as 1 somewhere else in your source using a condition such as

<Condition Message="You must uninstall MyApp first before running this installer.">INSTALLED or Not OLDVERSIONDETECTEDPROPERTY</Condition>

Also, Upgrade element (table entries) should be usable even if your UpgradeCode changed. You could define a "DetectOnly" search using the old UpgradeCode and use the existence of a detected ProductCode in the Condition (LaunchCondition table) element.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • I see it in the msi log. AppSearch: Property: TESTPROPERTY, Signature: MyApp MSI (c) (B0:C4) [15:55:01:915]: Note: 1: 2262 2: Signature 3: -2147287038 MSI (c) (B0:C4) [15:55:01:915]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE32\Software\MyApp 3: 2 Action ended 15:55:01: AppSearch. Return value 1. – Bianchi Apr 06 '15 at 20:56
  • @Bianchi return value 1 doesn't equate to the value of the property, it's the return code for the procedure performing the search. – Ryan J Apr 06 '15 at 20:59
  • @RyanJ - Shows my limited experience with this. Do you know of a way to get the value that a property is set to? – Bianchi Apr 06 '15 at 21:05
  • @ChristopherPainter - I was trying to keep it very generic. As mentioned in a response to another one of your answers on this page, this application's requirements are weird. The app is a common interface for different plugins. Each plugin is managed by a different group in the organization. There are currently 28 or so plugins. In your example, using the upgrade element, I'd have to check for each of the 28, correct? – Bianchi Apr 06 '15 at 21:10
  • @Bianchi what is being performed when you specify a registry search in the manner you've configured, is the property defined will contain the value of the registry key itself, if found. It's not a simple "1 if found, 0 if not". See [the reference](http://wixtoolset.org/documentation/manual/v3/xsd/wix/registrysearch.html). Basically what you need to do is get the value of the registry key, and display the message if it's defined to be anything. Though, this begs the question already asked, is why is an upgrade element not an option? – Ryan J Apr 06 '15 at 21:10
  • @RyanJ - I understand it's not a simple 1 or 0 answer but, if it doesn't exist, shouldn't NOT TESTPROPERTY work? As for why an upgrade element is not an option, has to do more as being a matter of simplicity. Above I mentioned there are 28 plugins for the app, and any one of those teams can patch the app. So using upgrade element means I need 28 checks :-S Not impossible, but was trying to do something simpler like checking for a registry key. – Bianchi Apr 06 '15 at 21:19
  • @Bianchi Return value 1" doesn't mean the property was returned as a 1 it simply means that the AppSearch action returned 1. TESTPROPERTY1 would have to have a value to be true. It does not have a value therefore the expression is false and the installer is blocked. – Christopher Painter Apr 06 '15 at 21:46
  • The negative -2147287038 is 0x8003002 which means not found. – Christopher Painter Apr 06 '15 at 21:58
  • @ChristopherPainter - So shouldn't NOT TESTPROPERTY work for the condition? It doesn't work in this case, but I read that as NOT FALSE, which is the same as true. And if the condition evaluates to true, it should install. Am I thinking about this correctly? – Bianchi Apr 06 '15 at 22:18
  • The condition does not evaluate to true. The property is an empty string so it evaluates to false. https://msdn.microsoft.com/en-us/library/aa368012(v=vs.85).aspx – Christopher Painter Apr 06 '15 at 22:29