2

I added a custom action that should kill my application using taskkill CMD when someone tries to uninstall it using the add/remove in the control panel using the following code :

<Property Id="TASKKILL">
        <DirectorySearch Id="SysDir" Path="[SystemFolder]" Depth="1">
            <FileSearch Id="taskkillExe" Name="taskkill.exe" />
        </DirectorySearch>
</Property>

<CustomAction Id="ServerKill" Property="TASKKILL" Execute="immediate" Impersonate="yes" Return="ignore" ExeCommand="/F /FI &quot;IMAGENAME EQ App.exe&quot;"/>

<InstallExecuteSequence>
    <Custom Action="ServerKill" After="FindRelatedProducts"/>   
</InstallExecuteSequence>

However this does not work. If someone can tell me how to fix it or even share a better/easier way to kill my app process I would be grateful.

p.s
also tried to use WMIC using cmd. That really didn't work and the installation itself did not finish at all because of this.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Zaya3161
  • 43
  • 1
  • 6

2 Answers2

4

Perhaps you can try the CloseApplication feature from the Util schema: http://wixtoolset.org/documentation/manual/v3/xsd/util/closeapplication.html

See here for an example code snippet: https://sourceforge.net/p/wix/mailman/message/20186650/


UPDATE: I ran some tests and this element works a little differently from what I expected. The first thing you need to add is the reference to the wixUtilExtension file. On the command line this is:

candle -ext WiXUtilExtension Test.wxs
light -ext WixUtilExtension Test.wixobj

In Visual Studio I think you simply add a project reference to WixUtilExtension.dll.

Then you simply add something like this to your wxs source file:

  <util:CloseApplication Id="CloseNotepad" Target="notepad.exe"
                         CloseMessage="yes" RebootPrompt="no">
  </util:CloseApplication>

And add this at the top of your wxs file:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" 
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

It looks like Wix takes care of the rest (custom actions and a custom table in your MSI with the list of processes to kill).


Here is my full test file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" 
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

   <Product Id="*" UpgradeCode="12345678-1234-1234-1234-111111111111" 
            Name="Example Product Name" Version="0.0.1" Manufacturer="Example Company Name" Language="1033">
      <Package InstallerVersion="200" Compressed="yes" Comments="Windows Installer Package"/>
      <Media Id="1" Cabinet="product.cab" EmbedCab="yes"/>
 
      <Directory Id="TARGETDIR" Name="SourceDir">
         <Component Id="ApplicationFiles" Guid="*">
        </Component>
      </Directory>
 
      <Feature Id="DefaultFeature" Level="1">
         <ComponentRef Id="ApplicationFiles"/>
      </Feature>

      <util:CloseApplication Id="CloseNotepad" Target="notepad.exe" CloseMessage="yes" RebootPrompt="no"></util:CloseApplication>
   </Product>
</Wix>

Links: Some related or marginally related links for easy retrieval.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Hi ,Thanks for the replay checked it out and i cant define CloseApplication element for some unknown reason. i get the following message : Setup.wxs(35) : error CNDL0200 : The Product element contains an unhandled extension element 'util:CloseApplication'. Please ensure that the extension for elements in the 'http://schemas.microsoft.com/wix/UtilExtension' namespace has been provided. WixUI_InstallDirNoLicense.wxs light.exe : error LGHT0093 : Could not find entry section in provided list of intermediates. Expected section of type 'Product'. – Zaya3161 Aug 30 '16 at 08:13
  • I added some detail to the answer above. – Stein Åsmul Aug 31 '16 at 18:54
1

Alternatively a simple VBScript scheduled to run on uninstall should do the job:

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
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164