Using ManagementClass

ManagementClass is a Common Information Model (CIM) management class. An example of a management class is a WMI class like Win32_LogicalDisk which hold information about the drives on a machine.

  1. The Constructor can take a WMI class path like “Win32_LogicalDisk”
  2. Get all the ManagementObject‘s by calling ManagementClass.GetInstances()
  3. Get all the PropertyData‘s by calling ManagementObject.Properties
            ManagementClass drives = new ManagementClass("Win32_LogicalDisk");

            foreach (ManagementObject managementObject in drives.GetInstances())
                Console.WriteLine("Name: \t" + managementObject["Name"]);

                foreach (PropertyData propertyData in managementObject.Properties)
                    if (propertyData.Value != null)
                        Console.WriteLine("\t" + propertyData.Name + ": " + propertyData.Value);


The System.Management namespace is required to use the ManagementClass.


No comments yet.

Add Yours

  • Author Avatar


Comment Arrow

About Author


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.