【发布时间】:2015-12-19 06:20:10
【问题描述】:
在 WiX 中,DirectorySearch 可用于确定目标计算机上是否存在特定目录。但我不明白是否有一致的方法来确定目录不存在。
例如:
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id='InstallDir' Type='directory'
Root='HKLM' Key='Software\Company\Product\Install' Name='InstallPath'/>
</Property>
<Property Id='IS_INSTALLED' Secure='yes'>
<DirectorySearch Id='IsInstalled' Path='[INSTALLDIR]' />
</Property>
当注册表项和目录都存在时,IS_INSTALLED 属性设置为DirectorySearch 返回的路径。
当目录不存在时,IS_INSTALLED 似乎设置为“C:\”。
是这样的条件:
<Condition>NOT (IS_INSTALLED = "C:\")</Condition>
检测找到目录的可靠方法?有没有更好的办法?
答案:这是我接受的基于mrnxs answer 的 WiX 代码
<Property Id="PRODUCT_IS_INSTALLED" Secure="yes">
<RegistrySearch Id='RegistrySearch1' Type='directory'
Root='HKLM' Key='Software\Company\Product\Version\Install' Name='Path'>
<DirectorySearch Id='DirectorySearch1' Path='[PRODUCT_IS_INSTALLED]'/>
</RegistrySearch>
</Property>
<CustomAction Id='SET_INSTALLDIR'
Property='INSTALLDIR'
Value='[PRODUCT_IS_INSTALLED]'/>
<InstallExecuteSequence>
<Custom Action='SET_INSTALLDIR' After='AppSearch'></Custom>
</InstallExecuteSequence>
【问题讨论】:
标签: installation wix