Reference the System.ServiceProcess.dll first, and use the namespace System.ServiceProcess:
We write the code sample as the following:
using System;
using System.ServiceProcess;
class Program
{
static void Main(string[] args)
{
ServiceController sc = new ServiceController("Server");
string svStatus = sc.Status.ToString();
if (svStatus == "Stopped")
{ sc.Start(); }
if (svStatus == "Running")
{ sc.Stop(); }
}
}
No comments:
Post a Comment