Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# how do i query the list of running services on a windows server?

Tags:

c#

windows

I want to query for a list of services running as a specific user on a remote machine and then check the health of each. I'm building a custom console.

like image 844
kkelly18 Avatar asked May 09 '09 02:05

kkelly18


People also ask

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.

What is '~' in C programming?

In mathematics, the tilde often represents approximation, especially when used in duplicate, and is sometimes called the "equivalency sign." In regular expressions, the tilde is used as an operator in pattern matching, and in C programming, it is used as a bitwise operator representing a unary negation (i.e., "bitwise ...

What is operators in C?

An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators − Arithmetic Operators.

What is the use of in C?

In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more.


1 Answers

ServiceController.GetServices("machineName") returns an array of ServiceController objects for a particular machine.

This:

namespace AtYourService {     using System;     using System.ServiceProcess;      class Program     {         static void Main(string[] args)         {             ServiceController[] services = ServiceController.GetServices();              foreach (ServiceController service in services)             {                 Console.WriteLine(                     "The {0} service is currently {1}.",                     service.DisplayName,                     service.Status);             }              Console.Read();         }     } } 

produces:

The Application Experience service is currently Running.  The Andrea ST Filters Service service is currently Running.  The Application Layer Gateway Service service is currently Stopped.  The Application Information service is currently Running.  etc... 

Of course, I used the parameterless version to get the services on my machine.

like image 85
Aaron Daniels Avatar answered Sep 28 '22 05:09

Aaron Daniels