3

I have run into challenging problem trying to accomplish the following: my application installs a service (watchdog.exe) and an exe file (app.exe).

After the installation is done the service starts and creates process "app.exe".

during uninstall I want to kill the process "app.exe" (which is running under local system account, so I must be running as admin).

problem 1: The installs says that it requires a reboot since it sees that file "app.exe" is being held (running) during the CostFinalize phase (please correct me if I'm wrong about the phase that checks if a reboot will be required). It would be much better to kill the process when the uninstallation begins. I have verified that if the process is not running during the uninstall then the install does not complain about a reboot required.

problem 2: using a custom action to kill the process is problematic. the action must run elevated, but on the other hand it must run before the costFinalize (otherwise - it's back to problem 1).

I would appreciate any suggestion. Also, any alternative solutions (is there another way to close the process maybe during install that will not require a reboot?)

The custom action code I have now (not good since it both unnecessarily asks for a reboot and fails to kill the process due to lack of permissions):

<InstallExecuteSequence>
  <!--<ScheduleReboot After="InstallFinalize" />-->
  <Custom Action="MyProcess.TaskKill" Before="InstallValidate"></Custom>
</InstallExecuteSequence>

<!--<Property Id="Net">Net.exe</Property>-->
<Property Id="QtExecCmdLine" Value='"[%SYSTEMROOT]\System32\taskkill.exe" /F /IM App.exe' />
<CustomAction Id="MyProcess.TaskKill"
              BinaryKey="WixCA"
              DllEntry="CAQuietExec"
              Execute="immediate"
              Return="ignore" />

Here is the log for the failure:

CAQuietExec: Error 0x80070001: Command line returned an error. CAQuietExec: Error 0x80070001: CAQuietExec Failed CustomAction MyProcess.TaskKill returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 18:15:54: MyProcess.TaskKill. Return value 1603.

Steven V
  • 16,357
  • 3
  • 63
  • 76
OSH
  • 2,847
  • 3
  • 25
  • 46

1 Answers1

1

There are few ideas that I have, namely:

  • Use EventWaitHandles, which allow processes to communicate between each other, and delegate your wish to app.exe. Your app.exe can then terminate, as needed. This is clean solution and should be prefered.

If for whatever reason you decide to kill the application like you don't care about anything at all in the world, then you can:

Basically there are so many hackery tricks you can do, to kill the application. Such as using WiX Burn and requiring administration rights, then doing your thing. I would go with solution#1(create your own mechanisms)

By the way, if you use ServiceControl element in WiX, it will STOP the service before REINSTALLING/UNISTALLING. You can hook to OnStop() method in Service and kill your App.exe there. If you have set Service as App.exe parent, then there should be flag that any child processes die with parent.

Community
  • 1
  • 1
Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
  • Due to security reasons, I prefer to kill the app "like I don't care about anything else". Running the installer as admin right from the start would solve my problem, but so far the 2'nd solution did not work for me - wix started of normally and requested elevation only during setup (after failing to kill the process and letting me know it needs a reboot). I will try playing around with solution #2 some more to see if I can get it to work. – OSH Nov 12 '13 at 04:02
  • Well, it's already unsecure to let other applications kill your application. Imagine your software doing something, and it gets killed for no good reason. This is asking for a trouble. – Erti-Chris Eelmaa Nov 14 '13 at 11:23