Start or Stop Windows Service with c#

Start a service

Boolean StartService(String name)
{
	try
	{
		System.ServiceProcess.ServiceController service = 
                    new System.ServiceProcess.ServiceController();
		service.ServiceName = name;
		service.Start();
		return true;
	}
	catch
	{
		return false;
	}
}

Stop a service

Boolean StopService(String name)
{
	try
	{
		System.ServiceProcess.ServiceController service = 
                   new System.ServiceProcess.ServiceController();
		service.ServiceName = name;
		service.Stop();
		return true;
	}
	catch
	{
		return false;
	}
}
Categories: C# Tags: , , ,
%d bloggers like this: