ServiceController sc = new ServiceController("serviceName");
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.Refresh();
}
if (sc.Status == ServiceControllerStatus.Stopped || sc.Status == ServiceControllerStatus.StopPending)
{
sc.Start();
sc.Refresh();
}