using System;
using System.ServiceProcess;
class MainClass
{
public static void Main()
{
ServiceController scAlerter = new ServiceController("Alerter");
Console.WriteLine(scAlerter.DisplayName);
Console.WriteLine(scAlerter.CanStop);
scAlerter.Stop();
Console.WriteLine("Service stopped");
scAlerter.Start();
Console.WriteLine("Service started");
}
}
Alerter
False
Unhandled Exception: System.InvalidOperationException: Cannot stop Alerter service on computer '.'.
---> System.ComponentModel.Win32Exception: The service has not been started
--- End of inner exception stack trace ---
at System.ServiceProcess.ServiceController.Stop()
at MainClass.Main()