Create ManagementObjectSearcher to query Win32_Service : ManagementClass « Windows « C# / C Sharp






Create ManagementObjectSearcher to query Win32_Service

 
using System;
using System.Management;

public class Sample 
{
    public static void Main(string[] args) 
    {
        ManagementObjectSearcher s = 
            new ManagementObjectSearcher(
            "root\\CIMV2", 
            "SELECT * FROM Win32_Service", 
            new EnumerationOptions(
            null, System.TimeSpan.MaxValue,
            1, true, false, true, 
            true, false, true, true));
        foreach (ManagementObject service in s.Get()) 
        {
            // show the service
            Console.WriteLine(service.ToString());
        }
    }
}

   
  








Related examples in the same category

1.Enumerate ManagementClass
2.Initialize a ManagementClass and list its methods
3.Initialize a ManagementClass and Get the properties in the class
4.Initialize a ManagementClass and Get the Qualifiers in the class