.NET Zone is brought to you in partnership with:

Amir Ahani (Microsoft Most Valuable Professional) is expert in Microsoft .NET technologies such as C# and he spends most of his time teaching and consulting internationally. He has been teaching advanced Microsoft courses at British Columbia Institute of Technology (BCIT) since 2003. In addition, he is a member of and speaker at the following communities: DevTeach, .netBC, Vancouver Technology Festival, ASQ, APICS, PMI, NPA, and ITAC. Amir is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

Installed Windows Services in C#

08.22.2012
| 1662 views |
  • submit to reddit

















The following code checks whether a Windows service is installed on your machine or not:

public static void ISWindowsServiceInstalled(string serviceName)
{
    // get list of Windows services
    ServiceController[] services = ServiceController.GetServices();
 
    foreach (ServiceController service in services)
    {
        if (service.ServiceName == serviceName)
            return true;
    }
    return false;
}

 

Published at DZone with permission of Amir Ahani, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: