基于用户选择的Wix条件注册表写入

Posted

技术标签:

【中文标题】基于用户选择的Wix条件注册表写入【英文标题】:Wix conditional registry writing based on the user choice 【发布时间】:2016-11-03 07:47:04 【问题描述】:

我使用 WiX 3.9 和 WixUI_Advanced 对话框来创建 Windows 安装程序。用户可以选择在本地或每台机器(所有用户)安装应用程序。为此,我使用 WixPerUserFolder 属性。

<Publish Dialog="InstallScopeDlg" Control="Next" Property="WixAppFolder" Value="WixPerUserFolder" Order="1">!(wix.WixUISupportPerUser) AND NOT Privileged</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="1" Order="8">WixAppFolder = "WixPerUserFolder"</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="MSIINSTALLPERUSER" Value="" Order="9">WixAppFolder = "WixPerMachineFolder"</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="ALLUSERS" Value="" Order="3">WixAppFolder = "WixPerUserFolder"</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="ALLUSERS" Value="1" Order="2">WixAppFolder = "WixPerMachineFolder"</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="APPLICATIONFOLDER" Value="[WixPerUserFolder]" Order="4">WixAppFolder = "WixPerUserFolder"</Publish>

<Publish Dialog="InstallScopeDlg" Control="Next" Property="APPLICATIONFOLDER" Value="[WixPerMachineFolder]" Order="5">WixAppFolder = "WixPerMachineFolder"</Publish>

根据用户选择(WixPerUserFolder 或 WixPerMachineFolder),我还希望能够选择注册表项:HKCU 或 HKLM。

如果用户选择本地安装,那么:

<RegistryKey Root="HKCU" Key="$(var.RegKey)" ForceDeleteOnUninstall="yes" ForceCreateOnInstall="yes">
         <RegistryValue Type="string" Value="" KeyPath="yes" />
         <RegistryValue Type="string" Name="InstallDir" Value="[INSTALLDIR]"/>
</RegistryKey>

否则:

<RegistryKey Root="HKLM" Key="$(var.RegKey)" ForceDeleteOnUninstall="yes" ForceCreateOnInstall="yes">
    <RegistryValue Type="string" Value="" KeyPath="yes" />
        <RegistryValue Type="string" Name="InstallDir" Value="[INSTALLDIR]"/>
</RegistryKey>

【问题讨论】:

【参考方案1】:

Root="HKMU" 将根据包是按用户还是按机器运行来选择正确的配置单元。

【讨论】:

以上是关于基于用户选择的Wix条件注册表写入的主要内容,如果未能解决你的问题,请参考以下文章

WiX:有条件地注册应用程序以在 Windows 启动时启动

WiX安装选项--环境变量

WIX - 在注册表中写入属性

(WiX) 将产品信息写入注册表以用于双重用途安装程序

Wix v3.7 - 写入注册表值时出错

在 wix 安装期间搜索注册表更改