Retrieve a List of the Services Running on your Computer using C#

Retrieve a List of the Services Running on your Computer using C#

The ServiceController class can be used to retrieve a list of the services running on your computer. The GetServices() can be used to do so. Here’s an example to list the services that are running on your machine

Add a reference to System.ServiceProcess.

Then write the following code:


using System;
using System.ServiceProcess;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
ServiceController[] sController =
ServiceController.GetServices();
foreach (ServiceController sc in sController)
{
if (sc.Status.ToString() == "Running")
{
Console.WriteLine(sc.ServiceName);
}
}
Console.ReadLine();
}
catch (Exception ex)
{
// handle ex
}
}
}
}

Leave a Reply