I am using the service controller executecommand function, like so:
ServiceController serviceController = new ServiceController("a Service",
Environment.MachineName);
serviceController.ExecuteCommand(129);
And in the service controller:
protected override void OnCustomCommand(int command)
{
base.OnCustomCommand(command);
// Depending on the integer passed in, the appropriate method is called.
switch (command)
{
case 129:
RestartSpooler();
break;
case 131:
InstallPrinter();
break;
case 132:
DeletePrinter();
break;
}
}
However, despite calling any of the commands from the calling code (the code hits the line, then steps over, no exceptions), nothing happens. Why? This is all on the local machine and I have full admin rights.
Thanks
You must be trying to execute command against a stopped service. Add something like the following: