How to read WMI data of a USB (PnP) device, in this case the hardware ids, in C#? -


how can hardware id usb device? know how id device-manager, want via c#. possible? i´ve done already, delivers me not hardware if consists of vendor id (vid) , product id (pid):

managementobjectsearcher usb = new managementobjectsearcher("select * win32_diskdrive interfacetype='usb'"); managementobjectcollection usbinfo = usb.get();  foreach (managementobject mo in usbinfo) {     serialnumber = (string)mo["deviceid"];     name = (string)mo["name"];     drives.add(new keyvaluepair<string, string>(name, serialnumber)); } 

i tried "pnpdeviceid" , "serialnumber" instead of "deviceid", doesn´t replys hardware-id need.

in console application, add refrence-->.net-->system.management-->add

namespace consoleapplication1 {   using system;   using system.collections.generic;   using system.management; // need add system.management project references.    class program   {     static void main(string[] args)     {       var usbdevices = getusbdevices();        foreach (var usbdevice in usbdevices)       {         console.writeline("device id: {0}, pnp device id: {1}, description: {2}",             usbdevice.deviceid, usbdevice.pnpdeviceid, usbdevice.description);       }        console.read();     }      static list<usbdeviceinfo> getusbdevices()     {       list<usbdeviceinfo> devices = new list<usbdeviceinfo>();       managementobjectcollection collection;        using (var searcher = new managementobjectsearcher(@"select * win32_usbhub"))         collection = searcher.get();              foreach (var device in collection)       {         devices.add(new usbdeviceinfo(         (string)device.getpropertyvalue("deviceid"),         (string)device.getpropertyvalue("pnpdeviceid"),         (string)device.getpropertyvalue("description")         ));       }        collection.dispose();       return devices;     }   }    class usbdeviceinfo   {     public usbdeviceinfo(string deviceid, string pnpdeviceid, string description)     {       this.deviceid = deviceid;       this.pnpdeviceid = pnpdeviceid;       this.description = description;     }      public string deviceid { get; private set; }     public string pnpdeviceid { get; private set; }     public string description { get; private set; }   } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -