Wix not writing to HKCU when run with a user needing admin login?

34 views Asked by At

I'm writing a wix4 bundle installer for am Office COM Addin Dll, which needs to write a bunch of registry entries in HKCR (so for the machine) to register the Dll and then a few entries in HKCU to tell Office that the Dll exists.

At the moment, I have AppComponents.wxs containing:

<Wix ...>
  <Fragment ...>
    <ComponentGroup ...>
      <Component ...>
        <File Id="..." Source="...">

        <!-- Register classes in HKCR for COM -->
        <RegistryValue Root="HKCR" Key=...>
        <RegistryValue Root="HKCR" Key=...>

        <!-- Tell Office about it for this user in HKCU -->
        <RegistryValue Root="HKCU" Key="Software\Microsoft\VBA\VBE\6.0\Addins ...>

That works well for most cases, except when a non-admin user tries to run the install. In that case, the Admin login prompt pops up fine and if I type in an admin pwd, all the HKCR entries get written, but the HKCU ones get written to the User hive for the admin account that authorised the install, not the user account that's running it.

How do I configure the installer to write to the logged-in user's HKCU hive, not the admin's?

I only seem to be able to control whether the wix4 bundle does a user/machine install by setting the 'Scope' parameter of the MSIs in the bundle.

By trying the different combinations, I find:

  • With a perUser install, everything goes to HKCU as you'd hope, but Excel then fails to load the Addin - as if it's requiring some of the COM registration entries to be in HKLM.
  • With a perMachine install, everything goes to HKLM as you'd hope, but Excel then fails to see the 'COM Addin Registration' entries - it only looks in HKCU for them.

In other words, Excel seems to only work properly if some of the COM Addin registry entries are in HKLM and some are in HKCU.

I've been able to get something working by including a small exe that adds/removed the 'COM Addin Registration' for the logged-on user (whether run as admin or not), then running that as a CustomAction at the end of the install / start of uninstall.

I think I need a parameter on the Wix4 RegistryValue element to say "Always write to the HKCU hive of the logged in user, not the HKCU hive of the UAC admin account" - the latter being what seems to happen.

The following is the entirety of a Wix4 install, just writing two registry entries:

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Package Name="RegSample" Manufacturer="ATest" Version="1.0.0.0" UpgradeCode="7339450f-45bf-4986-9adc-e6ddf928d922" Scope="perMachine">
        <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
        <StandardDirectory Id="ProgramFiles6432Folder">
            <Directory Id="INSTALLFOLDER" Name="ATest" />
        </StandardDirectory>
        <ComponentGroup Id="ExampleComponents" Directory="INSTALLFOLDER">
            <Component>
                
                <!-- Must get written to HKLM, so needs a perMachine install with an Admin user login-->
                <RegistryValue Root="HKCR" Key="ATest.SampleClass" Value="SampleProject.SampleClass" Type="string" Action="write" />

                <!-- Must get written to the HKCU hive of the logged-in user, not the Admin-->
                <RegistryValue Root="HKCU" Key="Software\ATest\AKey" Name="Description" Value="SomeValue" Type="string" Action="write" />

            </Component>
        </ComponentGroup>
        <Feature Id="Main">
            <ComponentGroupRef Id="ExampleComponents" />
        </Feature>
    </Package>
</Wix>

If I build it as an MSI and run the MSI on a normal user's account, it works fine: I get a UAC prompt, type in an Admin's login, the HKCR entry gets written to HKLM and the HKCU entry gets written to the logged-in user's hive. I can then uninstall it fine, too.

If I now put the MSI in a bundle:

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
  <Bundle Name="RegSampleBundle" Manufacturer="ATest" Version="1.0.0.0" UpgradeCode="9e82d5ae-2812-4220-8142-0c1d13735e96">
    <BootstrapperApplication>
      <bal:WixStandardBootstrapperApplication LicenseUrl="https://www.example.com/license" Theme="hyperlinkLicense" />
    </BootstrapperApplication>
    <Chain>
        <MsiPackage Id="SAMPLE" SourceFile="RegSample.msi"/>
    </Chain>
  </Bundle>
</Wix>

Build and run the exe, I get the same UAC prompt, but the HKCU entry gets written into the Admin account's HKCU hive.

1

There are 1 answers

3
Christopher Painter On

You're snippet doesn't show critically important properties such as ALLUSERS and MSIINSTALLPERUSER. The fact that your getting a UAC prompt tells me that these are not set to per-user but rather then per-machine.