Services help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Lazarchik

    Services help

    Hello:

    We manufacture tools used in the Semiconductor industry that have a DB
    engine running on each one. I need to scan through the computers on the
    company domain and find which ones have this service installed and it's
    current state ( paused, running, stopped, etc ). Can anyone point me to a
    set of classes in C# that allow me to find running services on computers
    within a Domain?

    Thanks for your help

    Bob Lazarchik
    SDI.


  • Glenn

    #2
    Re: Services help

    Bob

    Check out the System.ServiceP rocess.ServiceC ontroller type.

    ServiceControll er iisService = new ServiceControll er();

    try
    {
    iisService.Mach ineName = "MyServer";
    iisService.Serv iceName = "IISADMIN";

    if ( iisService.Stat us == ServiceControll erStatus.Stoppe d )
    {
    Console.WriteLi ne( "Eek! Get help the websites down" );
    }
    }
    catch ( System.InvalidO perationExcepti on )
    {
    Console.WriteLi ne( "OOPS! The machine doesn't have the service
    installed" );
    }

    HTH

    Glenn

    "Bob Lazarchik" <bob5407@sditam pa.com> wrote in message
    news:ugS6o$oiEH A.2356@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hello:
    >
    > We manufacture tools used in the Semiconductor industry that have a DB
    > engine running on each one. I need to scan through the computers on the
    > company domain and find which ones have this service installed and it's
    > current state ( paused, running, stopped, etc ). Can anyone point me to a
    > set of classes in C# that allow me to find running services on computers
    > within a Domain?
    >
    > Thanks for your help
    >
    > Bob Lazarchik
    > SDI.
    >
    >[/color]


    Comment

    • Scott Allen

      #3
      Re: Services help


      Hi Bob:

      Here is an article describing a script to enumerate services on remote
      machines:


      You should be able to port this to C# using classes in the
      System.Manageme nt namespace.

      HTH,

      --
      Scott



      On Wed, 25 Aug 2004 06:37:58 -0400, "Bob Lazarchik"
      <bob5407@sditam pa.com> wrote:
      [color=blue]
      >Hello:
      >
      >We manufacture tools used in the Semiconductor industry that have a DB
      >engine running on each one. I need to scan through the computers on the
      >company domain and find which ones have this service installed and it's
      >current state ( paused, running, stopped, etc ). Can anyone point me to a
      >set of classes in C# that allow me to find running services on computers
      >within a Domain?
      >
      >Thanks for your help
      >
      >Bob Lazarchik
      >SDI.
      >[/color]

      Comment

      • Glenn

        #4
        Re: Services help

        Bob/Scott

        Very useful article, here's the C# version....

        ConnectionOptio ns co = new ConnectionOptio ns();
        co.Username = "userName";
        co.Password = "password";

        ManagementScope scope = new ManagementScope ( @"\\myServer\ro ot\cimv2", co );
        ObjectQuery query = new ObjectQuery( "select * from win32_service" );
        ManagementObjec tSearcher mos = new ManagementObjec tSearcher( scope, query );
        ManagementObjec tCollection moc = mos.Get();

        foreach ( ManagementObjec t mo in moc )
        {
        Console.WriteLi ne( "{0} : {1}", mo["Name"].ToString(),
        mo["State"].ToString() );
        }

        Check this link out for more info on Win32_Service

        win32_service.a sp

        HTH

        Glenn

        " <bitmask@[nospam].fred.net> wrote in message
        news:498pi0h9id ntd06it0aa3avpj m9esc2ncb@4ax.c om...[color=blue]
        >
        > Hi Bob:
        >
        > Here is an article describing a script to enumerate services on remote
        > machines:
        > http://www.microsoft.com/technet/com...ts/sg1102.mspx
        >
        > You should be able to port this to C# using classes in the
        > System.Manageme nt namespace.
        >
        > HTH,
        >
        > --
        > Scott
        > http://www.OdeToCode.com
        >
        >
        > On Wed, 25 Aug 2004 06:37:58 -0400, "Bob Lazarchik"
        > <bob5407@sditam pa.com> wrote:
        >[color=green]
        > >Hello:
        > >
        > >We manufacture tools used in the Semiconductor industry that have a DB
        > >engine running on each one. I need to scan through the computers on the
        > >company domain and find which ones have this service installed and it's
        > >current state ( paused, running, stopped, etc ). Can anyone point me to[/color][/color]
        a[color=blue][color=green]
        > >set of classes in C# that allow me to find running services on computers
        > >within a Domain?
        > >
        > >Thanks for your help
        > >
        > >Bob Lazarchik
        > >SDI.
        > >[/color]
        >[/color]


        Comment

        • Scott Allen

          #5
          Re: Services help

          Very cool, Glenn.

          --
          Scott

          On Wed, 25 Aug 2004 17:19:37 +0100, "Glenn" <csharp@blackwi nter.net>
          wrote:
          [color=blue]
          >Bob/Scott
          >
          >Very useful article, here's the C# version....
          >
          >ConnectionOpti ons co = new ConnectionOptio ns();
          >co.Username = "userName";
          >co.Password = "password";
          >
          >ManagementScop e scope = new ManagementScope ( @"\\myServer\ro ot\cimv2", co );
          >ObjectQuery query = new ObjectQuery( "select * from win32_service" );
          >ManagementObje ctSearcher mos = new ManagementObjec tSearcher( scope, query );
          >ManagementObje ctCollection moc = mos.Get();
          >
          >foreach ( ManagementObjec t mo in moc )
          >{
          > Console.WriteLi ne( "{0} : {1}", mo["Name"].ToString(),
          >mo["State"].ToString() );
          >}
          >
          >Check this link out for more info on Win32_Service
          >http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
          >win32_service. asp
          >[/color]

          --
          Scott

          Comment

          Working...