WIX 3.10 - write to HKLM

时间:2016-04-15 15:04:49

标签: installation wix windows-installer registry

I'm trying to write a registry value to HMLM using WIX installer, but no luck so far.

I have read official documentation, and some related information. Pitty, but official doc only says how to write to HKLU, that does not suit my needs.

I have also looked at some questions like Cannot create registry key value with WiX installer but if I try doing like this and put it in

I have x86 installer and also tried to follow recomendation for writing to Software\Wow6432Node, but no luck.

May be there is some difference in setting it in 3.10 version? Can someone write example including some surroundings to figure out how and where shoud the value be put to create a registry folder + key-values on install and delete them on uninstall?

Thank you very much.

1 个答案:

答案 0 :(得分:3)

要写入注册表,您需要添加< RegistryValue>元素作为子元素到< Component>。

在简短的代码片段中,我创建了一个组件,它将注册表项添加到HKLM \ SOFTWARE \ $(var.RegistryRootKeyName)\ v7的注册表中,名为" ClientPath"使用INSTALLDIR属性的值。

<DirectoryRef Id="BIN">
    <Component Id="program.exe">
        <File Id="program.exe" KeyPath="yes" Source="$(var.BinariesDir)\_bin\program.exe" />
        <Shortcut       
            Id="ClientInstallDirShortcut" 
            Name="$(var.Product) $(var.InstallerVersion)" 
            Directory="INSTALLDIR"
            Target="[#program.exe]" 
            WorkingDirectory="BIN"/>
        <RegistryValue  
            Id="ClientInstallDirRegShortcut" 
            Root="HKLM" 
            Key="SOFTWARE\$(var.RegistryRootKeyName)\v7"                                         
            Type="string"
            Name="ClientPath"
            Value="[INSTALLDIR]"/>
    </Component>
</DirectoryRef>

现在,要创建此注册表,您需要在安装期间安装的功能中包含该组件。

<Feature Id="ClientMain" Title="Client" Level="1" >
    <ComponentRef Id="program.exe" />
</Feature>

由于您拥有此注册表位置,因此一旦卸载与该组件相关的所有内容,Windows安装程序将自动删除注册表项,如果它们为空,则会自动删除这些文件夹。

我认为您遇到的问题与HKLM \ SOFTWARE \ Wow6432Node的混淆有关。您实际上不必在注册表项中指定Wow6432Node。如果你这样做,那么你的注册表项可能会转到HKLM \ SOFTWARE \ Wow6432Node \ Wow6432Node \ ...

有两种观点&#39;您可以在64位计算机上打开/创建注册表项时看到的注册表。您可以使用32位视图或64位视图。

当您使用32位视图时,Wow6432Node会自动插入到HKLM \ SOFTWARE \ ...的注册表键路径中。您可以通过添加Win64 =&#34; yes&#34;来强制64位视图。您的registryvalue元素,但您应该确保您只是尝试在64位计算机上写入或读取64位注册表。

注册表使用的默认视图与进程的位数相关联。如果您在64位计算机上运行64位进程安装程序,要访问32位注册表位置,您需要设置Win64 =&#34; no&#34; (我认为这是它的工作原理)。类似于32位安装程序,默认视图是32位注册表,它自动将Wow6432Node添加到您的HKLM \ SOFTWARE注册表项。