WindowsFolder属性作为exe地址的一部分不起作用

Ric*_*dMc 3 installation wix

尝试让wix安装程序终止进程,根据我在网上发现的信息,这似乎是一种方法:

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="WindowsFolder" Name="WINDOWS"/>

<Property Id="QtExecCmdLine" Value='"[WindowsFolder]System32\taskkill.exe" /F /IM Foo.exe'/>
<CustomAction Id="KillTaskProcess" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="immediate" Return="ignore"/>
Run Code Online (Sandbox Code Playgroud)

我在构建项目时遇到的问题将引发有关Windows属性的以下错误:

The 'QtExecCmdLine' Property contains '[WindowsFolder]' in its value which is an illegal reference to another property.  If this value is a string literal, not a property reference, please ignore this warning.  To set a property with the value of another property, use a CustomAction with Property and Value attributes. 
Run Code Online (Sandbox Code Playgroud)

我尝试使用[#WindowsFolder]代替,它可以消除错误,但不能解决问题。使用完整地址(C:\ Windows \ System32 \ taskkill.exe)代替该值确实有效,但我想避免这种情况。

小智 5

我认为您无法以自己的方式引用目录(例如“ [WindowsFolder]”)。这种类型的注释用于引用属性的值。

WindowsInstaller已经提供了Public属性,该属性代表任何给定系统上的System Folder。您可以在32位计算机上使用[SystemFolder]来获取c:\ Windows \ System32(在64位计算机上注意,这将为您提供c:\ Windows \ SysWow64)。
因此,在64位计算机上,您可以使用[System64Folder],它将为您提供c:\ Windows \ System32

您的代码将如下所示

<Property Id="QtExecCmdLine" Value='"[SystemFolder]taskkill.exe" /F /IM Foo.exe'/>
Run Code Online (Sandbox Code Playgroud)

要么

<Property Id="QtExecCmdLine" Value='"[System64Folder]taskkill.exe" /F /IM Foo.exe'/>
Run Code Online (Sandbox Code Playgroud)


我在支持32和64位计算机的安装程序包中执行类似的操作。这会使事情稍微复杂化。
为了解决这个问题,我将尝试使用以下代码:

<Property Id="TASKKILLFILEPATH"/>
<Property Id="QtExecCmdLine" Value='"[TASKKILLFILEPATH]" /F /IM Foo.exe'/>
Run Code Online (Sandbox Code Playgroud)

然后,添加一个自定义操作以正确设置任务终止文件路径

<CustomAction Id='SetTASKKILLFILEPATH32' Property='TASKKILLFILEPATH' Value='[SystemFolder]\taskkill.exe' Return='check' />
<CustomAction Id='SetTASKKILLFILEPATH64' Property='TASKKILLFILEPATH' Value='[System64Folder]\taskkill.exe' Return='check' />
Run Code Online (Sandbox Code Playgroud)

在InstallExecuteSequence中,您可以根据系统类型运行适当的自定义操作:

<InstallExecuteSequence>
      <Custom Action='SetTASKKILLFILEPATH64' After='AppSearch'>VersionNT64</Custom>
      <Custom Action='SetTASKKILLFILEPATH32' After='AppSearch'>Not VersionNT64</Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)

BTW VersionNT64是WindowsInstaller提供的另一个属性。

这可能有点矫kill过正,我希望有其他人可以共享的简便方法,但是我知道这是一个可行的解决方案。希望这至少可以引导您朝正确的方向发展。