To find a service and if it works,
private static bool IsServiceInstalled(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
if (service.ServiceName == serviceName) return true;
return false;
}
private static bool IsServiceInstalledAndRunning(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
if (service.ServiceName == serviceName) return service.Status != ServiceControllerStatus.Stopped;
return false;
}
Note that it actually checks to see if it is stopped and not working, but you can change this if you want.
This is nice to do in compressed .NET constructs. Do not remember where I got the information from, but now it looks so simple and worth publishing.
John source
share