Windows – Stopping Windows service does not kill processes (service uses ant)

javaservicewindows

I have a Windows service on Windows Server 2008 R2 that I set-up using instsrv on the srvany.exe executable. The three values in the Parameters key are set as follows:

AppDirectory  C:\selenium-grid
Application   C:\ant\bin\ant.bat
AppParameters launch-hub

The service starts fine and two Java processes appear in the Task Manager when it starts (one process is ant and the other is a Java class launched by ant). When I stop the service the status of the service changes to stopped but the two Java processes do not go away.

How do I get the processes to stop when I stop the service?

Best Answer

Unvortunately, SRVANY sucks. There is an alternative which is the "Non-Sucking Service Manager" (NSSM) - it will shut down your application and all child processes on the service stop signal.