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"]);                
            }            
LVL 1
kvnsdrAsked:
Who is Participating?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.