Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

installation - 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='SoftwareCompanyProductInstall' 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='SoftwareCompanyProductVersionInstall' 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]MyCompanyMyProduct")
  • 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...