WiX - 如果注册表搜索失败,如何安装到备用路径



我的程序应该安装到注册表中记录的路径上。如果未找到注册表项,则安装到另一个(默认)路径。

例如,我想要这样的东西:

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='SoftwareMyAppFoo' Name='InstallDir' />
    if not found, then set "MYINSTALLDIR" to "D:workingdefaultApps"
</Property>    

我应该如何编写我的 wxs 文件来实现这一点?

编辑:

现在的问题是:

if not found in registry, then set "MYINSTALLDIR" to LocalAppDataFolder 

我试过了

<Property Id="MYINSTALLDIR" Value="LocalAppDataFolder">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='SoftwareMyAppFoo' Name='InstallDir' />
</Property>

但返回错误:

Error 1606. Could not access network location LocalAppDataFolder.

好的,我终于想出了该怎么做。

使用 Custom Action ,现在可以将默认值设置为另一个属性:

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='SoftwareMyAppFoo' Name='InstallDir' />
</Property>
<CustomAction Id="UserInstallDir" Property="InstallDir" Value="[INSTALLDIRCU]" Execute="immediate" />
<CustomAction Id="UserInstallDirDefault" Property="InstallDir" Value="[LocalAppDataFolder]" Execute="immediate" />
<InstallExecuteSequence>
    <Custom Action="UserInstallDir" After="AppSearch">MYINSTALLDIR</Custom>      
    <Custom Action="UserInstallDirDefault" After="AppSearch">NOT MYINSTALLDIR</Custom>      
</InstallExecuteSequence>

从内存中,下面的示例应该可以工作。如果未找到搜索的值,则该属性将获取默认值。仅当搜索成功时,才会覆盖它。

<Property Id="MYINSTALLDIR" Value="Default Property Value">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='SoftwareMyAppFoo' Name='InstallDir' />
</Property>

最新更新