0

I need to kill a running console app which is running in the background using tskill.exe however when I defive $(env.windir)\system32 I get the error below.

The CustomAction/@Directory attribute's value, 'C:\WINDOWS', is not a legal identifier. Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or periods (.). Every identifier must begin with either a letter or an underscore.

And the CustomAction I wrote to run tskill.exe is:

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

What is the correct way to achieve this?

EDIT: I realized I was using it the wrong way. Here's what I have now:

    <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>

Still doesn't work.

What I want to do is to kill a process (MyConsoleApp.exe) before install or uninstall begins.

What is wrong with the code?

  • 2
    Why are you not using the [`CloseApplication`](http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html) element? – zett42 Jun 27 '18 at 14:40
  • I tried. It tries to close the app but the process of the app still remains untouched. Strange thing is that the exe file was deleted after uninstall but I still see in the Task Manager the app is still up and running. It can't terminate the running process somehow. I guess this is because the exe doesn't have a frame the installer can close. – suat korkmaz Jun 28 '18 at 12:28

1 Answers1

-1

Here's how I did.

<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>
  • If this is your own application, maybe have a quick read of [**the Restart Manager section in this answer**](https://stackoverflow.com/questions/50917062/windows-installer-avoid-fileinuse-dialog-box-when-installing-a-package/50935008#50935008). – Stein Åsmul Jun 29 '18 at 17:25