问题
I have a super simple installer to test if a installer can write register entries under HKCU\Software\Classes\Wow6432Node (the msi is target x86 and I'm testing it on a Win7 x64 machine).
The problem is: it just does not want to write anything under Wow6432Node at all. Following is the code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="f671ee4d-dd0a-4f7f-a4d1-1d181d2f3002" Name="TestWow" Language="1033" Version="1.0.0.0" Manufacturer="X" UpgradeCode="5d030587-0b6f-4a55-b090-c97a4fd22d13">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser" InstallPrivileges="limited"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="XWix" Level="1">
<ComponentRef Id="TestWow" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir" />
</Fragment>
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="TestWow" Guid="f671ee4d-dd0a-4f7f-a4d1-1d181d2f3002">
**<RegistryKey Root="HKCU" Key="Software\Classes\TestWow">
<RegistryValue Name="Test" Value="Wow" Type="string" KeyPath="yes"/>
</RegistryKey>**
</Component>
</DirectoryRef>
</Fragment>
</Wix>
I've even tried to modify the registry part like:
<RegistryKey Root="HKCU" Key="Software\Classes\Wow6432Node\TestWow">
<RegistryValue Name="Test" Value="Wow" Type="string" KeyPath="yes"/>
</RegistryKey>
It still does not work.
Your help is much appreciated!
回答1:
I don't think hkcu is virtualised in the same way as hklm. You need to ensure your component is marked as a 32 bit one and any virtualization will be taken care of for you.
回答2:
You can create this key using custom action. Dot NET Framework 4.0 has a special feature (RegistryView) to read the 64 bit registry from 32 bit applications. Refer this document for more information. You need to write another custom action to remove this key in uninstall.
Custom Action:
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
key = key.OpenSubKey(@"Software\Classes\Wow6432Node", true);
key.CreateSubKey("TestWow").SetValue("Test", "Wow", RegistryValueKind.String);
return ActionResult.Success;
}
WiX:
<Binary Id="TestWow" SourceFile="CustomAction\TestProject\TestProject\bin\Release\TestProject.CA.dll" />
<CustomAction Id="TESTWOW" BinaryKey="TestWow" DllEntry="CustomAction1" Return="check" />
<Custom Action="TESTWOW" After="InstallInitialize" >Not Installed</Custom>
来源:https://stackoverflow.com/questions/16504395/wix-write-register-entries-under-hkcu-software-classes-wow6432node