WMI with System.Management: Get files filtered by criteria and without using WQL

262 Views Asked by At

I am trying to get files filtered by a path and extension via WMI using System.Management with C#.

I DO NOT want to use WQL (WMI Query) - (because its very slow for my purpuses)

I know how to get ALL CIM_DataFile objects, but I want to filter them BEFORE they are returned to the ManagementObjectCollection collection, otherwise I am getting a very long list which takes forever to run

Here is the code:

        ManagementPath path = new ManagementPath("CIM_DataFile");
        ManagementClass file_class = new ManagementClass(path);

        // I want to add a filter here which will add a filter to GetInstances()
        ManagementObjectCollection File_objects_collection = file_class.GetInstances();

        foreach (ManagementObject file in File_objects_collection)
        {
            Console.WriteLine(file["Name"].ToString());
        }

Thank you

0

There are 0 best solutions below