![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace ConsoleApplication1
{
class Program
{
static void Main( string [] args)
{
ServiceIsExisted( " MSSQLSERVER " );
}
private static bool ServiceIsExisted( string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == serviceName && s.Status == ServiceControllerStatus.Stopped)
{
s.Start();
return true ;
}
}
return false ;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
namespace ConsoleApplication1
{
class Program
{
static void Main( string [] args)
{
ServiceIsExisted( " MSSQLSERVER " );
}
private static bool ServiceIsExisted( string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == serviceName && s.Status == ServiceControllerStatus.Stopped)
{
s.Start();
return true ;
}
}
return false ;
}
}
}