Get system services with C#

To list system services, we are going to use ServiceController class. Add a reference to System.ServiceProcess namespace first.

try
{
    foreach (System.ServiceProcess.ServiceController s 
    	in System.ServiceProcess.ServiceController.GetServices())
         Console.WriteLine(s.Status + " -- " + s.ServiceName);
}
catch (Exception)
{
    //...
}
Categories: C# Tags: , , , ,
%d bloggers like this: