I'm developing an application to achieve work in background through a Windows Service. I've created the service thanks to the MSDN tutorial, and then I can Start or Stop it correctly.
My service also need to execute custom commands. Therefore, I've implemented the "OnCustomCommand" method in the service's class.
I can send custom execution commands with commands ID between 128 and 255, accordingly everything i've found on the net.
My problem is :
I can't execute command on the service when it's stopped. ExecuteCommand()
throws an System.InvalidOperationException
every time I call it on the serviceController
.
Cannot control <myservice> service on computer '.'
This does not happens when the service is running.
MSDN says
When you call ExecuteCommand, the status of the service does not change. If the service was started, the status remains Running. If the service was stopped, the status remains Stopped, and so on.
So I suppose this is actually possible to executeCommand
on stopped services.
My service is installed as LocalSystem service, and the serviceController
is run with administrator privileges.
Does anyone know how to resolve this?