Sponsored Ad

Tuesday, January 11, 2011

How to Check if Windows Service is Installed on System using C#

This code will help you to find specific service is installed on your machine or not. This program first find the list of services installed on your machine and then compare with given service.

How to Check if Windows Service is Installed on System using C#

Code : Find Windows Service

using System;
using System.ServiceProcess;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string find_service = "SQLWriter";
            ServiceController[] service_list = ServiceController.GetServices();
            bool bfound = false;

            foreach (ServiceController my_service_list in service_list)
            {
                if (find_service == my_service_list.ServiceName)
                {
                    Console.WriteLine(my_service_list.ServiceName + " is already installed.");
                    bfound = true;
                    break;
                }              
            }

            if(!bfound)
                Console.WriteLine(find_service + " is not installed.");
            Console.ReadLine();
        }
    }
}

1 comments:

Sponsored Ad

Website Update

Followers