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

时间:2014-07-25 10:40:10

标签: wix installation

试图让一个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"/>

我遇到的问题是构建项目会引发以下错误抱怨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. 

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

2 个答案:

答案 0 :(得分:2)

我认为您不能以您的方式引用目录(例如&#34; [WindowsFolder]&#34;)。此类注释用于引用属性的值。

WindowsInstaller已经提供了一个公共属性,它代表任何给定系统上的系统文件夹。 您可以在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'/>

或者

<Property Id="QtExecCmdLine" Value='"[System64Folder]taskkill.exe" /F /IM Foo.exe'/>


我在一个支持32和32的安装包中执行类似的操作。 64位机器。这使问题变得复杂。
为了解决这个问题,我会尝试使用您的代码:

<Property Id="TASKKILLFILEPATH"/>
<Property Id="QtExecCmdLine" Value='"[TASKKILLFILEPATH]" /F /IM Foo.exe'/>

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

<CustomAction Id='SetTASKKILLFILEPATH32' Property='TASKKILLFILEPATH' Value='[SystemFolder]\taskkill.exe' Return='check' />
<CustomAction Id='SetTASKKILLFILEPATH64' Property='TASKKILLFILEPATH' Value='[System64Folder]\taskkill.exe' Return='check' />

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

<InstallExecuteSequence>
      <Custom Action='SetTASKKILLFILEPATH64' After='AppSearch'>VersionNT64</Custom>
      <Custom Action='SetTASKKILLFILEPATH32' After='AppSearch'>Not VersionNT64</Custom>
</InstallExecuteSequence>

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

这可能有点矫枉过正,我希望有一种更容易的方法可以让别人分享,但我知道这是一个有效的解决方案。希望这至少会引导你进入正确的方向。

答案 1 :(得分:0)

为什么不使用VBScript来终止进程呢?这是一个标准脚本:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next