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.
For example:
<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>
When both the registry key and the directory exist, the IS_INSTALLED
property is set to the path returned by DirectorySearch
.
When the directory does not exist, IS_INSTALLED
appears to be set to "C:\".
Is a condition like:
<Condition>NOT (IS_INSTALLED = "C:\")</Condition>
a reliable way to detect that the directory was found? Is there a better way?
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>
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.
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:
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
or
NOT IS_INSTALLED
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With