ServiceController sc = new ServiceController("");
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped); //等待服务停止
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
}
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped); //等待服务停止
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
}
}