Wix工具包。如何使用$(env.windir)?

时间:2018-06-27 09:50:09

标签: c# installation wix

我需要使用tskill.exe杀死正在后台运行的正在运行的控制台应用程序,但是当我违反$(env.windir)\ system32时,会出现以下错误。

CustomAction / @ Directory属性的值'C:\ WINDOWS'不是合法的标识符。标识符可以包含ASCII字符A-Z,a-z,数字,下划线(_)或句点(。)。每个标识符都必须以字母或下划线开头。

我写来运行tskill.exe的CustomAction是:

<CustomAction Id="TaskKill" Impersonate="yes" Return="ignore" Directory="$(env.windir)" ExeCommand='"\system32\tskill.exe" /F /IM MyConsoleApp' TerminalServerAware="yes" Execute="deferred"/>

实现此目标的正确方法是什么?

编辑: 我意识到我使用错误的方式。这是我现在拥有的:

    <Property Id="TASKKILLFILEPATH"/>
    <Property Id="QtExecCmdLine" Value='"[TASKKILLFILEPATH]" /F /IM MyConsoleApp.exe'/>
    <CustomAction Id='SetTASKKILLFILEPATH32' Property='TASKKILLFILEPATH' Value='[SystemFolder]taskkill.exe' Return='check' />
    <CustomAction Id='SetTASKKILLFILEPATH64' Property='TASKKILLFILEPATH' Value='[System64Folder]taskkill.exe' Return='check' />

<InstallExecuteSequence>
      <RemoveExistingProducts Before="InstallInitialize" />

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

仍然无效。

我想做的是在安装或卸载开始之前终止一个进程(MyConsoleApp.exe)。

代码有什么问题?

1 个答案:

答案 0 :(得分:-1)

这就是我的做法。

<Property Id="cmdline">taskkill.exe /F /IM VClassConsole.exe</Property>

<CustomAction Id="SystemShell" Execute="deferred" Directory="TARGETDIR" ExeCommand='[cmdline]' Return="ignore" Impersonate="no"/>

<InstallExecuteSequence>
  <Custom Action="SystemShell" After="InstallInitialize"/>
</InstallExecuteSequence>