Checking Existing Windows Service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ann Marinas

    Checking Existing Windows Service

    Hi, All!

    I just would like to ask... Is it possible that you can detect whether a
    Windows Service is existing or not? If this is possible, how can you
    implement it?

    Thank you!

    A


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Checking Existing Windows Service

    Ann,

    The easiest way would be to use the classes in the System.Manageme nt
    namespace to perform a WMI query for the instance of Win32_Service that
    corresponds to the service you are looking for. This will let you determine
    whether the service exists, is it running, etc, etc.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Ann Marinas" <mallows98@hotm ail.com> wrote in message
    news:%23lzqE5PO EHA.644@tk2msft ngp13.phx.gbl.. .[color=blue]
    > Hi, All!
    >
    > I just would like to ask... Is it possible that you can detect whether a
    > Windows Service is existing or not? If this is possible, how can you
    > implement it?
    >
    > Thank you!
    >
    > A
    >
    >[/color]


    Comment

    • Ann Marinas

      #3
      Re: Checking Existing Windows Service

      Thank you so much. I really do appreciate the help!

      I'll try to apply this on my application.

      Thank you!

      Ann

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:%23UU7JHQO EHA.556@tk2msft ngp13.phx.gbl.. .[color=blue]
      > Ann,
      >
      > The easiest way would be to use the classes in the System.Manageme nt
      > namespace to perform a WMI query for the instance of Win32_Service that
      > corresponds to the service you are looking for. This will let you[/color]
      determine[color=blue]
      > whether the service exists, is it running, etc, etc.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Ann Marinas" <mallows98@hotm ail.com> wrote in message
      > news:%23lzqE5PO EHA.644@tk2msft ngp13.phx.gbl.. .[color=green]
      > > Hi, All!
      > >
      > > I just would like to ask... Is it possible that you can detect whether a
      > > Windows Service is existing or not? If this is possible, how can you
      > > implement it?
      > >
      > > Thank you!
      > >
      > > A
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Dave Girvitz

        #4
        Re: Checking Existing Windows Service

        If you don't want to work through the WMI query syntax, this may be a little
        easier:
        //required for using ServiceControll er
        using System.ServiceP rocess;

        private bool ServiceExists(s tring serviceName)
        {
        ServiceControll er[] allServices = ServiceControll er.GetServices( );
        bool result = false;
        ServiceControll er sc = null;
        for (int i = 0; i < allServices.Len gth; i++)
        {
        if (allServices[i].ServiceName.To Lower() == serviceName.ToL ower())
        {
        result = true;
        break;
        }
        }
        return result;
        }

        "Ann Marinas" <mallows98@hotm ail.com> wrote in message
        news:%23lzqE5PO EHA.644@tk2msft ngp13.phx.gbl.. .[color=blue]
        > Hi, All!
        >
        > I just would like to ask... Is it possible that you can detect whether a
        > Windows Service is existing or not? If this is possible, how can you
        > implement it?
        >
        > Thank you!
        >
        > A
        >
        >[/color]


        ---
        Outgoing mail is certified Virus Free.
        Checked by AVG anti-virus system (http://www.grisoft.com).
        Version: 6.0.668 / Virus Database: 430 - Release Date: 04/24/2004


        Comment

        Working...