3
votes

I am trying to create a WiX installer for a plugin of one of my applications but have come across something I find strange; perhaps it is the expected behavior but then I would like to know why.

My application saves its installation path in the following registry location:

HKEY_CURRENT_USER\SOFTWARE\MyCompany\MyApp\Installed

As default my application is installed to C:\Program Files\MyApp if x64 and C:\Program Files (x86)\MyApp if x86.

In my plugin installer I have the following in Product.wxs to retrieve the install path of my application:

<Property Id="MY_APP_DIR">
  <RegistrySearch Id='my_app_dir' Type='raw' Root='HKCU' Key='SOFTWARE\MyCompany\MyApp' Name='Installed' />
</Property>

I then added the following just to see what is actually retrieved when I run the installer:

<Condition Message="[MY_APP_DIR]">
  0  
</Condition>

In the case where "C:\Program Files\MyApp\" is stored in the registry I got the following when I run the plugin installer:

Plugin installer (x86): C:\Program Files (x86)\MyApp\

Plugin installer (x64): C:\Program Files\MyApp\

Why is not the value stored in the registry retrieved independently of which platform the msi was built for?

On a x64 machine only the x64 versions of my installers will be used so this should not cause any problems it just confuses me.

EDIT: As requested I have included my entire Product.wxs:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="TestInstaller" Language="1033" Version="1.0.0.0" Manufacturer="MyCompany" UpgradeCode="SOME_GUID">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Property Id="MY_APP_DIR">
        <RegistrySearch Id="my_app_dir" Root="HKCU" Key="SOFTWARE\MyCompany\MyApp" Name="Installed" Type="raw" />
    </Property>

    <Condition Message="[MY_APP_DIR]">
        0
    </Condition>

    <Feature Id="ProductFeature" Title="TestInstaller" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="INSTALLFOLDER" Name="TestInstaller">
      <Directory Id="MY_APP_DIR" Name="MyAppInstallPath">
        <Directory Id="MyAppBinFolder" Name="bin" />
      </Directory>
    </Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <ComponentGroup Id="ProductComponents">
      <Component Id="ProductComponent" Guid="SOME_GUID" Directory="MyAppBinFolder">
        <File Id="Foo.Bar" Source="Foo.Bar" KeyPath="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>
1
Could you provide more details on how MY_APP_DIR is used in your WiX installer? For example is it referenced in a Directory element? - bradfordrg
@bradfordrg I don't have the code with me right now but yes, I do use it in a Directory element. As a direct child to the <Directory Id="TARGETDIR" Name="SourceDir"> element if I remember correctly. - dbostream

1 Answers

3
votes

Windows Installer has a rule called WIN64DUALFOLDERS which does not allow 32 bit installers to write to 64 bit locations. If you run your 32 bit installer on a 64 bit computer with diagnostic logging enabled you should see a section in the log file like this:

AppSearch: Property: MY_APP_DIR, Signature: my_app_dir
MSI (c) (BC:F4) [10:00:47:953]: Note: 1: 2262 2: Signature 3: -2147287038 
MSI (c) (BC:F4) [10:00:47:953]: WIN64DUALFOLDERS: 'C:\Program Files (x86)\' will substitute 17 characters in 'C:\Program Files\MyCompany\MyApp' folder path. (mask argument = 0, the folder pair's iSwapAttrib member = 0).
MSI (c) (BC:F4) [10:00:47:953]: PROPERTY CHANGE: Adding MY_APP_DIR property. Its value is 'C:\Program Files (x86)\MyCompany\MyApp'.
Action ended 10:00:47: AppSearch. Return value 1.

Even though the path in the registry is C:\Program Files\, Windows Installer automatically redirects it to C:\Program Files (x86)\.

For more information see Disable WIN64DUALFOLDERS substitution in WIX.

Note: I deleted my previous answer because with the benefit of hindsight it wasn't useful.