Csharp/C Sharp by API/System.ServiceProcess/ServiceController
Содержание
new ServiceController
<source lang="csharp"> using System; using System.ServiceProcess; public 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"); }
}
</source>
ServiceController.CanStop
<source lang="csharp"> using System; using System.ServiceProcess; public 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"); }
}
</source>
ServiceController.DisplayName
<source lang="csharp"> using System; using System.ServiceProcess; public 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"); }
}
</source>
ServiceController.Stop()
<source lang="csharp"> 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"); }
}
</source>