【问题标题】:Detecting the presence of a directory at install time在安装时检测目录的存在
【发布时间】: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


    【解决方案1】:

    当属性用作基于属性的文件夹时,通常会发生这种情况。在这种情况下,CostFinalize 操作会自动将属性设置为有效路径(例如“C:\”),以便 Windows Installer 可以使用该文件夹。

    由于此路径是自动生成的,因此您无法确定它在所有客户端计算机上都是“C:\”,因此您不应在您的条件下使用此值。相反,你可以试试这个:

    • 为您的文件夹使用自定义属性
    • 使用类型51 custom action(使用格式化文本设置的属性)将此属性设置为有效的默认路径(例如“[ProgramFilesFolder]MyCompany\MyProduct”)
    • 使用其他属性进行搜索
    • 使用其他类型 51 自定义操作将文件夹属性设置为您的搜索属性

    例如,如果您的搜索是 IS_INSTALLED,则您的文件夹可以使用 IS_INSTALLED_PATH。 IS_INSTALLED_PATH 可以设置为默认路径,并且在 AppSearch 操作之后,如果搜索发现某些内容,您可以将其设置为 IS_INSTALLED。

    这种方式可以用于调理:

    IS_INSTALLED
    

    NOT IS_INSTALLED
    

    【讨论】:

    • 嗨 Cosmin,感谢您提供详细信息。我遇到的问题是,您的其中一个步骤基本上让我留下了最初的问题。您说“...如果搜索找到某些东西,您可以将其设置为 IS_INSTALLED”。 AppSearch 似乎总能找到“某物”,即使它是操作系统驱动器的根目录。
    • 只有当该属性与您的 MSI 中的文件夹相关联时,搜索属性才会设置为根驱动器。如果您删除该关联(例如通过使用文件夹的另一个属性),则搜索属性在找不到任何内容时应该为空。基本上,您的搜索属性应该只供搜索使用,以确保它按照您想要的方式设置。
    【解决方案2】:

    了解 AppSearch 的 RegLocator 和 DrLocator 模式可能有点棘手。我建议暂时忽略该条件并记录安装以验证 AppSearch 是否正确设置了您想要的属性。先解决你在这方面发现的问题。当它工作时,该属性将设置为注册表的值或目录的路径。

    那么你应该可以使用:

    <Condition>IS_INSTALLED/>   <!-- it's not important what the value is, just that it exists -->
    <Condition>Not IS_INSTALLED/>
    

    顺便说一句,我会避免使用属性 INSTALLDIR。在我的安装程序( InstallShield )中,作为安装的主要焦点具有特殊意义。

    【讨论】:

      【解决方案3】:

      另一种方法可能是这样,如果您想将 InstallDir 设置到其他任何位置,如果 SystemDir 和 RegisteryDir 不相同,您可以继续安装顺序

      <Property Id="RegisteryDir" Secure="yes">
      <RegistrySearch Id='InstallDir' Type='directory'
      Root='HKLM' Key='Software\Company\Product\Install' Name='InstallPath'/>
      </Property>
      <Property Id='SystemDir' Secure='yes'>
      <DirectorySearch Id='IsInstalled' Path='[RegisteryDir]' />
      </Property>
      <CustomAction Id="SET_INSTALL_DIR" Property="INSTALLDIR" Value="[SystemDir] />
      
      <InstallExecuteSequence>
      <Custom Action='SET_INSTALLDIR' After='AppSearch'>
      SystemDir AND SystemDir=RegisteryDir
      </Custom>
      </InstallExecuteSequence> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-12
        • 1970-01-01
        • 2020-01-24
        • 1970-01-01
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多