2

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

例如,我想要类似的东西:

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
    if not found, then set "MYINSTALLDIR" to "D:\working\defaultApps"
</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='Software\MyApp\Foo' Name='InstallDir' />
</Property>

但错误返回:

Error 1606. Could not access network location LocalAppDataFolder.
4

2 回答 2

6

好的,我终于知道该怎么做了。

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

<Property Id="MYINSTALLDIR">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' 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>
于 2012-08-15T06:23:34.873 回答
4

根据记忆,下面的示例应该可以工作。如果没有为搜索找到值,则该属性将获取默认值。只有在搜索成功时才会被覆盖。

<Property Id="MYINSTALLDIR" Value="Default Property Value">
    <RegistrySearch Id='MyRegistry' Type='raw' Root='HKCU' Key='Software\MyApp\Foo' Name='InstallDir' />
</Property>
于 2012-08-09T00:06:00.217 回答