Link to home
Start Free TrialLog in
Avatar of kvnsdr
kvnsdr

asked on

ManagementClass vs. ManagementObjectSearcher?

I find various articles concerning WMI information querries. Both example work the same.

Which code below is better?

ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");

            foreach (ManagementObject mo in mc.GetInstances())
            {
                listBox1.Items.Add(mo["SerialNumber"].ToString());
            }


ManagementObjectSearcher find = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

            foreach (ManagementObject mo in find.Get())
            {
                listBox1.Items.Add("Serial#... " + mo["SerialNumber"]);                
            }            
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't think better is the question here.  They both perform the same thing about the same efficiency, just in a slightly different way.  It's more about how you choose to implement.

Bob
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial