N
N
NameOf Var2017-12-01 10:33:51
C++ / C#
NameOf Var, 2017-12-01 10:33:51

How to programmatically get a list of all device properties in Device Manager?

Hi all!
There was an idea to write an application similar to USBDeview (an application that displays all currently connected USB devices). I also want to implement the functionality of turning on / off the USB device according to the schedule (USBDeview can also do this). All manipulations are carried out through requests to WMI. Faced a number of problems:
1. When you connect a new USB device, two devices appear - USB Mass Storage Device and Disk Drive. Which one to turn on / off so that the USB device is properly disconnected?
2. The request "select * from Win32_PnpEntity" returns a rather meager set of properties (for example, the parameters I need are missing, such as Matching device Id, Class, Is connected, etc. - all these parameters are in the Device Manager'e in the Details tab) . This is where the question comes from. How to display ALL properties that are in Device Manager'e?
Small code example:

spoiler
using System;
using System.Management;

namespace TestRequest
{
    class Program
    {
        static void Main(string[] args)
        {
           ManagementObjectCollection collection;
            using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnpEntity"))
                collection = searcher.Get();

            foreach (var device in collection)
            {
                Console.WriteLine("===================================");
                foreach (var prop in device.Properties)
                    Console.WriteLine("\t{0} : {1}", prop.Name, prop.Value);
                Console.WriteLine("===================================");
            }

            collection.Dispose();

            Console.Read();
        }
    }
}

When connecting a flash drive, two new devices appear:
Disk Drive 5a2104e473c94284327513.png
USB Mass Storage Device 5a2104f89913c951240432.png
I need to get a list of these properties: 5a21058491bce799301529.png
Please tell me which direction should I go?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NameOf Var, 2017-12-04
@hax

Solution:
https://ru.stackoverflow.com/a/753705/226766

D
Dmitry Chernyakov, 2017-12-01
@Kubatai

1. To disable, use USB Mass Storage Device
2. For more information about devices, use the query: "Select * From Win32_USBHub"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question