msbuildtasks icon indicating copy to clipboard operation
msbuildtasks copied to clipboard

ServiceController: StopAndKill

Open ipashchuk opened this issue 10 years ago • 0 comments

I would like to propose a new feature for the ServiceController task: StopAndKill. This new command would also kill the process started by the service in addition to stopping the service.

The reason for this feature is to handle a situation whereby a service stops but its associated process continues to run. In the ideal world, this would never happen because this indicates a design flaw in the service but that's a separate rant...

The process started by a service can be easily determined using WMI (or System.Management wrapper) as shown here: http://stackoverflow.com/questions/1574019/how-to-determine-windows-diagnostics-process-from-servicecontroller

The logic would be as follows:

  1. Get the process ID of the process started by a service
  2. Stop the service
  3. If the process is still running, shut it down

I, of course, would be happy to implement it assuming that there are no reasonable objections from the community to this feature.

ipashchuk avatar Apr 21 '14 17:04 ipashchuk