I have created a tool which offers similar functionality as the PSExec tool from Microsoft, but does this from Java (Without the "Exec" Command) https://dev.c-ware.de/confluence/display/PUBLIC/JRWShell+-+A+Java+library+for+remote+controlling+a+windows+shell
My problem is that normally my lib automatically stops and uninstalls the service it created, but in case of communication failure this does not happen automatically. I would like the dynamically created Service to start and listen for connections and to terminate after the connection is closed. Ideally I would like the Windows Service to terminate itself and uninstall itself automatically, but I think the self-uninstalling might not be possible without using a second Watchdog service that automatically cleanes up stopped services.
So my question is: Is it possible for a service to uninstall itself? If it is, how is this done and if it is not possible how can I make a service stop itself?