Reading Device Manager's Property Fields in Windows 7/8

Raulp picture Raulp · Feb 21, 2013 · Viewed 11.5k times · Source

I am developing a windows application which gives the field details --> X.

Where X is -->

Right Click My Computer >

    Properties >

          Device Manager > (select any Item - Say KeyBoard) >

                   Click it > standard PS/2 KeyBoard >

                                double Click standard PS/2 KeyBoard >

                                           click the Details Tab >

Under the Property there are various fields like Display Name , Problem Code,Parent Siblings, etc , etc?

I want to get their values . Which Windows API I can use for this. I am doing this for windows 7 as well as windows 8.I hope the API will remain the same.Also i am having 64 bit machine. This has to be true for any device whose details I wanted to know from the Device Manager.

ALso I just want to all operations - Reading and No Set (writing) so I think I will not be having any problem with violating the Admin Rights.PLease suggest.! I have added Snapshots for reference!Say for example I want to know the current State of the HID USB Complaint Mouse(D0(Active) or D2(Sleep)).

Image Showing the Powerdata Field for HID Compliant Mouse

Image Showing the Power State for HID Complaint Mouse That is D0 - Active

I need to Get this Power State D0.

Answer

Toan Nguyen picture Toan Nguyen · Mar 5, 2013

It's quite easy to get the hardware information using ManagementObjectCollection.

For instance to get all properties and values from the PC processor

var win32DeviceClassName = "win32_processor";
            var query = string.Format("select * from {0}", win32DeviceClassName);

            using (var searcher = new ManagementObjectSearcher(query))
            {
                ManagementObjectCollection  objectCollection = searcher.Get();

                foreach (ManagementBaseObject managementBaseObject in objectCollection)
                {
                    foreach (PropertyData propertyData in managementBaseObject.Properties)
                    {
                        Console.WriteLine("Property:  {0}, Value: {1}", propertyData.Name, propertyData.Value);
                    }
                }



            }

The full list of WIN32 class name is available at http://msdn.microsoft.com/en-us/library/aa394084%28v=VS.85%29.aspx

Cheers.