C# Windows Service Method to Determine if a Service is Installed, and Running

Needed to check some servers to make sure a Windows service was available, so wrote this code to keep an eye on them today:
public static bool IsServiceInstalled(string serviceName)
// get list of Windows services
ServiceController[] services = ServiceController.GetServices();

// try to find service name
foreach (ServiceController service in services)
if (service.ServiceName == serviceName)
return true;
return false;

public bool IsWindowsWindowsServiceRunning(string windowsServiceName, string windowsServiceHost ) ServiceController sc = new ServiceController(windowsServiceName, windowsServiceHost);


return (sc.Status == ServiceControllerStatus.Running);


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.