在安装时检测目录的存在 [英] Detecting the presence of a directory at install time
问题描述
在WiX中,DirectorySearch
可用于确定目标计算机上是否存在特定目录.但是我不知道是否有一致的方法来确定目录不存在.
In WiX DirectorySearch
can be used to determine if a specific directory exists on the target computer. But I don't understand if there's a consistent way to determine that a directory does not exist.
例如:
<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
返回的路径.
When both the registry key and the directory exist, the IS_INSTALLED
property is set to the path returned by DirectorySearch
.
当目录不存在时,IS_INSTALLED
似乎设置为"C:\".
When the directory does not exist, IS_INSTALLED
appears to be set to "C:\".
是类似这样的情况:
<Condition>NOT (IS_INSTALLED = "C:\")</Condition>
检测目录是否已找到的可靠方法?有更好的方法吗?
a reliable way to detect that the directory was found? Is there a better way?
答案:这是基于我接受的 mrnxs答案的WiX代码
Answer: Here is WiX code based on mrnxs answer that I accepted
<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>
推荐答案
通常,当该属性用作基于属性的文件夹时,会发生这种情况.在这种情况下,CostFinalize操作会自动将属性设置为有效路径(例如"C:\"),以便Windows Installer可以使用该文件夹.
Usually this happens when the property is used as a property-based folder. In this case the CostFinalize action automatically sets the property to a valid path (for example "C:\") so the folder can be used by Windows Installer.
由于此路径是自动生成的,因此您不能确定在所有客户端计算机上该路径都将是"C:\",因此您不应在情况中使用此值.相反,您可以尝试以下方法:
Since this path is generated automatically, you cannot be sure that it will be "C:\" on all your client machines, so you shouldn't use this value in your condition. Instead, you can try this:
- 为文件夹使用自定义属性
- 使用类型 51个自定义操作 (使用格式文本设置的属性)将此属性设置为有效的默认路径(例如"[ProgramFilesFolder] MyCompany \ MyProduct")
- 使用其他属性进行搜索
- 使用其他类型51自定义操作将folder属性设置为您的搜索属性
- use a custom property for your folder
- use a type 51 custom action (property set with formatted text) to set this property to a valid default path (for example "[ProgramFilesFolder]MyCompany\MyProduct")
- use another property for the search
- use another type 51 custom action to set the folder property to your search property
例如,如果搜索为IS_INSTALLED,则文件夹可以使用IS_INSTALLED_PATH.可以将IS_INSTALLED_PATH设置为默认路径,并且在AppSearch操作之后,如果搜索发现某些内容,则可以将其设置为IS_INSTALLED.
For example, if your search is IS_INSTALLED your folder can use IS_INSTALLED_PATH. IS_INSTALLED_PATH can be set to a default path and after AppSearch action you can set it to IS_INSTALLED if the search found something.
您可以通过这种方式进行调节:
This way you can use for conditioning:
IS_INSTALLED
或
NOT IS_INSTALLED
这篇关于在安装时检测目录的存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!