ManagementClass vs. ManagementObjectSearcher?

Posted on 2006-05-05
Last Modified: 2008-02-01
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())

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

            foreach (ManagementObject mo in find.Get())
                listBox1.Items.Add("Serial#... " + mo["SerialNumber"]);                
Question by:kvnsdr
    LVL 96

    Expert Comment

    by:Bob Learned
    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.

    LVL 96

    Accepted Solution

    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.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now