Q:

Wix: How to write to 32bit registers on 64 bit machine

I was looking for solution for some time but without success. I must admitt that I am begginer with wix. I have got one project (WPF + caliburn, using Visual Studio 2015) beeing compiled separately for x86 and x64. I use x64 machine to create both MSIs. Unfortunately during installation the setup always writes to 64bit registers which causes problems for the application.
I have created following components, trying to fix it using Win64="no" entry, unfortunately with no success. Can somone please advice correct component configuration?
<DirectoryRef Id="TARGETDIR">
  <?if $(var.Platform)="x64"?> 
          <Component Id="Registry_DefaultStoragePath" Guid="123-456-789" Win64="yes">
              <RegistryKey Root="HKLM"
                                       Key="Software\KeyName" Action="createAndRemoveOnUninstall">
                  <RegistryValue Type="string" Name="DefaultStorageLocation" Value="[DEFAULTSTORAGE]" KeyPath="yes"/>
              </RegistryKey>
          </Component>

          <Component Id="Registry_InstallType" Guid="123-456-789" Win64="yes">
              <RegistryKey Root="HKLM"
                                       Key="Software\KeyName" Action="createAndRemoveOnUninstall" >
                  <RegistryValue Type="string" Name="InstallType" Value="[INSTALLTYPE]" KeyPath="yes"/>
              </RegistryKey>
          </Component>
  <?endif?>
  <?if $(var.Platform)="x86"?> 
          <Component Id="Registry_DefaultStoragePath" Guid="132-456-789" Win64="no">
              <RegistryKey Root="HKLM"
                                       Key="Software\KeyName" Action="createAndRemoveOnUninstall">
                  <RegistryValue Type="string" Name="DefaultStorageLocation" Value="[DEFAULTSTORAGE]" KeyPath="yes"/>
              </RegistryKey>
          </Component>

          <Component Id="Registry_InstallType" Guid="123-456-789" Win64="no">
              <RegistryKey Root="HKLM"
                                       Key="Software\KeyName" Action="createAndRemoveOnUninstall" >
                  <RegistryValue Type="string" Name="InstallType" Value="[INSTALLTYPE]" KeyPath="yes"/>
              </RegistryKey>
          </Component>
  <?endif?>    

 

A:

The main problem is that <?if $(var.Platform)="x64"?> is handled by the preprocessor, so it is evaluated at compile-time, not runtime.
In order to handle x86/x64 runtime you can do this:
<component ....>
  <condition>NOT VersionNT64</condition>
  <!-- 32 bit component -->
  <!-- Add component content here -->
</component>
<component ....>
  <condition>VersionNT64</condition>
  <!-- 64 bit component -->
  <!-- Add component content here -->
</component>

