Home > Programming > Check for a Windows service in C#.

Check for a Windows service in C#.

January 10th, 2010 Jimmy Leave a comment Go to comments


This code will check through a list of installed Windows Services for a specific service name in C# (returns boolean). The function allows you to pass a service name as a string and the function will check the Windows Service list for that name. It will also look for partial service names in case you don’t know the exact name of the service.

     public bool IsBonjourInstalled(string sname)
        {
            ServiceController[] services_array = ServiceController.GetServices();
            foreach (ServiceController service in services_array)
            {
                if (service.ServiceName.Contains(sname))
                    return true;
            }
            return false;
        }
Digg: DIGG ME
  1. No comments yet.
  1. No trackbacks yet.