Natalie Carr
Natalie Carr

Reputation: 3797

One registry key for many products not deleted on uninstall

My company has many products, we want to create a registry key Software\$(var.Manufacturer)that will have all of our products if our customers have installed more than one (which is likely) I then want to have a secondary key for each of our products which get removed on uninstall but the main one does not. I have tried to achieve this like below but my main key gets deleted so all of my other products also get deleted from the registry. I know this is trivial but I cannot find an answer.

<DirectoryRef Id="TARGETDIR">
  <Component Id="Registry" Guid="*" MultiInstance="yes" Permanent="yes">
    <RegistryKey Root="HKLM" Key="Software\$(var.Manufacturer)" ForceCreateOnInstall="yes">
      <RegistryValue Type="string" Name="Default" Value="true" KeyPath="yes"/>
    </RegistryKey>
  </Component>
</DirectoryRef>

<DirectoryRef Id="TARGETDIR">
  <Component Id="RegistryEntries" Guid="*" MultiInstance="yes" >
    <RegistryKey Root="HKLM" Key="Software\$(var.Manufacturer)\[PRODUCTNAME]" Action="createAndRemoveOnUninstall">
      <RegistryValue Type="string" Name="Installed" Value="true" KeyPath="yes"/>
      <RegistryValue Type="string" Name="ProductName" Value="[PRODUCTNAME]"/>
    </RegistryKey>
  </Component>
</DirectoryRef>

EDIT: I have got my registry keys to stay using the following code. However they only all delete wen all products are deleted, not one by one as they need to.

<DirectoryRef Id="TARGETDIR">
  <Component Id="Registry" Guid="FF75CA48-27DE-430E-B78F-A1DC9468D699" Permanent="yes" Shared="yes" Win64="$(var.Win64)">
    <RegistryKey Root="HKLM" Key="Software\$(var.Manufacturer)" ForceCreateOnInstall="yes">
      <RegistryValue Type="string" Name="Default" Value="true" KeyPath="yes"/>
    </RegistryKey>
  </Component>
</DirectoryRef>

<DirectoryRef Id="TARGETDIR">
  <Component Id="RegistryEntries" Guid="D94FA576-970F-4503-B6C6-BA6FBEF8A60A" Win64="$(var.Win64)" >
    <RegistryKey Root="HKLM" Key="Software\$(var.Manufacturer)\[PRODUCTNAME]" ForceDeleteOnUninstall="yes">
      <RegistryValue Type="string" Name="Installed" Value="true" KeyPath="yes"/>
      <RegistryValue Type="string" Name="ProductName" Value="[PRODUCTNAME]"/>
    </RegistryKey>
  </Component>
</DirectoryRef>

Upvotes: 2

Views: 1075

Answers (1)

Christopher Painter
Christopher Painter

Reputation: 55581

Guid="*" probably disn't going to work well for you here. You need to use a static GUID ( probably in a fragment so it can be shared by multiple products ) with the Shared attribute set to true. You can do it the way you are doing it for the subkeys.

This way MSI will properly reference count the parent key and know when to delete it.

Upvotes: 1

Related Questions