• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

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"]);                
            }            
0
kvnsdr
Asked:
kvnsdr
  • 2
1 Solution
 
Bob LearnedCommented:
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
0
 
Bob LearnedCommented:
Actually, based on your other question, you can specify where conditions with the Searcher.  You might also be able to with the ManagementClass, but I am not sure how.

Bob
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now