Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting the presence of a directory at install time

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>
like image 234
Brian Gillespie Avatar asked Feb 08 '11 19:02

Brian Gillespie


1 Answers

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:

  • 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

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
like image 105
rmrrm Avatar answered Nov 15 '22 11:11

rmrrm