I am trying to send a command to my service TestService from a program running as administrator, I am able to start/stop it just fine, but whenever I try to ExecuteCommand() I encounter an Exception:
Cannot control service on computer '.'.
try
{
System.ServiceProcess.ServiceController service = new System.ServiceProcess.ServiceController("TestService");
if (service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
service.ExecuteCommand(100); // Causes Exception every time
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw e;
}
This is happening is because ExecuteCommand only accepts integers: 128-256, anything under 128 is system reserved and since 100 is being passed the Exception occurs.
Replacing service.ExecuteCommand(100) with something like service.ExecuteCommand(130) will work just fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With