Multiple alpr processes running after start/stop service

I am using
sc start “OpenALPR Agent”
and
sc stop “OpenALPR Agent”
from another application to start/stop the number plate processing.

However when I do this a few times I find that multiple alpr processes are running and I can not stop the cpu usage.

If you watch this video (turn down the sound) you will see multiple agent uptimes, and that I can’t stop the service:
https://1drv.ms/v/s!AkzhXDS3CLCalO5qk2SP4hQSjCFllw?e=r1Yat2

Windows service management is a little clunky. It can timeout and the service may still start. I don’t think “sc” gives enough control to gauge the status. If this is helpful, here is code we use (it triggers via cygrunsrv.exe which is in the bin directory):

std::string service_name = “”;
switch (service)
{
case AGENTSERVICE: service_name = “OpenALPR Agent”; break;
case LINKSERVICE: service_name = “OpenALPR Link”; break;
case QUEUESERVICE: service_name = “OpenALPR Queue”; break;
default: break;
}
// Use cygrunsrv to drive stop/start of the Windows service
if (operation == OPENALPR_SERVICE_START)
command << “/C cygrunsrv -S “” << service_name << “””;
else if (operation == OPENALPR_SERVICE_STOP)
command << “/C cygrunsrv -E “” << service_name << “””;
else if (operation == OPENALPR_SERVICE_RESTART)
{
command << “/C cygrunsrv -E “” << service_name << “” & cygrunsrv -S “” << service_name << “””;
}
else if (operation == OPENALPR_SERVICE_ENABLE)
{
command << “/C sc config “” << service_name << “” start= auto”;
//return setServiceStartupMode(service_name.c_str(), true);
}
else if (operation == OPENALPR_SERVICE_DISABLE)
{
command << “/C sc config “” << service_name << “” start= demand”;
//return setServiceStartupMode(service_name.c_str(), false);
}

int64_t response_code = (int64_t) ShellExecute(0, “runas”, “cmd.exe”, command.str().c_str(), 0, SW_HIDE);
std::cout << "Executing command: " << command.str() << " – response: " << response_code << std::endl;
bool success = response_code < 0 || response_code > 32;

if (success && !async &&
(operation == OPENALPR_SERVICE_START || operation == OPENALPR_SERVICE_STOP || operation == OPENALPR_SERVICE_RESTART))
{

Thanks for that!
That worked a charm.

I had some troubles running cygrunsrv in admin mode from CMD but I got that sorted out.