C# - Get List Of Windows Services

This code snippet demonstrates how to get a list of windows services with status information.

Program.cs

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.ServiceProcess;  
  6.  
  7. namespace ConsoleApplication1  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.  
  14.             ServiceController[] services = ServiceController.GetServices();  
  15.  
  16.             foreach (ServiceController sController in services)  
  17.             {  
  18.                 Console.WriteLine(sController.ServiceName + " " + sController.Status);  
  19.             }  
  20.  
  21.             Console.ReadKey();  
  22.         }  
  23.     }  
  24. }  

No comments:

Post a Comment