从文件完整路径检查文件版本

Check file version from file full path

我需要在继续安装之前检查服务可执行版本。

我已从注册表中读取注册服务的完整路径:

    <Property Id="SOME_SERVICE_PATH">
       <RegistrySearch Id="FindServicePath" Type="raw" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\TARGET_SERVICE" Name="ImagePath" />
    </Property>  

之后我尝试执行如下文件搜索:

  <Property Id="TARGET_SERVICE_UNSUPPORTED">
    <DirectorySearch Id="ServiceParticularVersionSearch" Path="[SOME_SERVICE_PATH]">
        <FileSearch Name="Service.exe" MaxVersion="2.5.0.1"  /> 
    </DirectorySearch>
  </Property>

这并没有给我结果。

我想问题出在我传递给 DirectorySearch Path 属性 的值中。 根据 Wix documentaion Path 应该初始化为 "Path on the user's system. Either absolute, or relative to containing directories" 不幸的是,注册表中没有我可以读取服务安装目录的地方。这是 3d 派对组件。

这里有什么解决办法吗?重要时刻 - 禁止在我们的项目中使用自定义操作

事实证明,答案在 RegistrySearch 元素的 Type 参数中。如果我将“文件”分配给它,我将能够在我阅读的路径上应用 FileSearch 并检查可执行版本。 这里的另一个解决方案是使用来自 RegistrySearch Element documentation

的评论

file

The registry value contains the path to a file. To return the full file path you must add a FileSearch element as a child of this element; otherwise, the parent directory of the file path is returned.

我的意思是“否则返回文件路径的父目录”

解决方案 1

  <Property Id="TARGET_SERVICE_UNSUPPORTED">
    <RegistrySearch Id="FindServicePath" Type="file" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\TARGET_SERVICE" Name="ImagePath" />
        <FileSearch Name="Service.exe" MaxVersion="2.5.0.1"  /> 
    </DirectorySearch>
  </Property>

解决方案 2

<Property Id="SOME_SERVICE_PATH">
   <RegistrySearch Id="FindServicePath" Type="file" Root="HKLM" Key="SYSTEM\CurrentControlSet\Services\TARGET_SERVICE" Name="ImagePath" />
</Property>

<Property Id="TARGET_SERVICE_UNSUPPORTED">
  <DirectorySearch Id="ServiceParticularVersionSearch" Path="[SOME_SERVICE_PATH]">
    <FileSearch Name="Service.exe" MaxVersion="2.5.0.1"  /> 
  </DirectorySearch>
</Property>