4

I'm using Wix to create an.msi installation file. when I uninstall my application, it's somehow still working and I can see it in the task manager.

I've tried Deferred execution for a custom action as described in the Wix documentation: https://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html but unfortunately, it's not working with me. the command that I want to execute is "taskkill /f /im myProcess.exe"

<Property Id="myProcessKill" Value="taskkill /f /im myProcess.exe"/>
<CustomAction Id="myProcessKill" BinaryKey="WixCA" DllEntry="WixQuietExec"
            Execute="deferred" Return="check" Impersonate="no"/>

<InstallExecuteSequence>
  <Custom Action="myProcessKill" After="InstallValidate"/>
</InstallExecuteSequence>

this makes my msi file gives an error during the installation. and if i changed Return="check" to Return="ignore", the msi completes the installation but it doesn't kill my process upon uninstall. what's wrong with the code above? or is there any other way to kill my process upon un install? Thanks in advance

Elamir Ohana
  • 292
  • 3
  • 20
  • Maybe have a read on the [**Restart Manager feature**](https://stackoverflow.com/a/48842663/129130). And there is a [**more detailed version here**](https://stackoverflow.com/a/50935008/129130) (see section "Setup Overkill"). – Stein Åsmul May 21 '19 at 14:16
  • I haven't checked this in detail for uninstall scenarios, but it should be worth a read. Restart Manager essentially closes applications in a controlled way, saving data as appropriate. – Stein Åsmul May 21 '19 at 14:24
  • @SteinÅsmul Thanks for your comment but i don't want to reboot after uninstall do you know another solution – Elamir Ohana May 21 '19 at 15:10
  • It wasn't about the rebooting, it was about the controlled shutdown of the application and the potential to restart it using the Restart Manager feature. I am not sure if it works properly on uninstall. [See this technical piece from Advanced Installer](https://www.advancedinstaller.com/user-guide/qa-vista-restart-manager.html). It is better to have your application shut itself down gracefully than to kill it. – Stein Åsmul May 21 '19 at 15:15

2 Answers2

3

Try to use cmd.exe with quotes and pass taskkill to that, in your case

<Property Id="myProcessKill" Value="&quot;c:\windows\system32\cmd.exe&quot; /c taskkill /f /im myProcess.exe"/>

I'm also not sure about your custom action in sequence, at least your should add REMOVE="ALL". In our app we are using <Custom Action="CloseApplication" Before="InstallInitialize"> <![CDATA[ NOT UPGRADINGPRODUCTCODE AND REMOVE="ALL" ]]> </Custom>

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
  • Thanks a lot for your answer but, is there a way not to specify the c partition, because the user may install the windows on another directory?? on your app, did you specify the c partition? Thanks again – Elamir Ohana May 21 '19 at 14:55
  • @ElamirOhana It's a quite interesting case, never faced with this issue in production with a thousands of users:) But you can try to use _SystemRoot_ environment variable for that – Pavel Anikhouski May 21 '19 at 14:59
  • i don't want to reboot after uninstall. how did you implement "CloseApplication" Custom Action in your app? – Elamir Ohana May 21 '19 at 15:05
  • The sample above doesn't require any reboots – Pavel Anikhouski May 21 '19 at 15:24
  • 1
    This solution worked perfectly thanks been trying for days to get this working. I finally setup a blank msi project and inserted lines to test. – dgxhubbard Dec 07 '20 at 21:53
3

Maybe try: WiX's CloseApplication Element. I would try that before trying anything else to avoid dependencies to any binaries. Found this sample on github.com (untested).

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164