title: WiX Preserve registry during major upgrade but remove on uninstall
body: <p>I would like to preserve all registry values (all contained within a single key) during an MSI major upgrade, but I would like the values deleted (as usual) when the application is uninstalled.</p>
  
  <p>I believe I need to use <a href="https://wixtoolset.org/documentation/manual/v3/xsd/wix/registrysearch.html" rel="nofollow noreferrer">RegistrySearch</a> to achieve this, reading the values individually to properties. </p>
  
  <p>I understand this can be achieved using the following markup:</p>
  
  <pre><code>&lt;Property Id="EXISTINGAPIKEY"&gt;
    &lt;RegistrySearch Id="name_of_dword"
      Root="HKLM"
      Key="Software\SomeCompany\SomeApp"
      Name="api_key"
      Type="raw" /&gt;
  &lt;/Property&gt;
  </code></pre>
  
  <p>I have now saved the value of <code>HKLM:\Software\SomeCompany\SomeApp\api_key</code> to a property called <code>EXISTINGAPIKEY</code>.</p>
  
  <p>The next step is to write this value back to the registry once the upgrade has completed, but before the service (which is installed/updated by the package) is started.</p>
  
  <p>So the questions are:</p>
  
  <ol>
  <li>How can I write this property back to the registry after the update but before the service is started? </li>
  <li>How can I ensure this only happens during an upgrade, and that the registry is cleaned during an uninstall? </li>
  </ol>
  
  <p>A good chance that I'm over-thinking this!</p>