0

In my WinForms application, I want to get a list of connected USB objects and then obtain the model property of those connected USB devices, as I need to be able to tell the user when they have connected a certain USB device or not.

Can anyone share an approach, via WMI or something else perhaps, to both get a list of connected devices and get the model property of those devices? I've adapted some code from this question on using WMI to get device information. The code below works fine but the parameters that are obtained ("DeviceID", "PNPDeviceID" etc.) aren't useful at all when it comes to identifying the devices in human understandable terms and I don't know how to get the Model property that is shown in Devices and Printers as seen here.

public static List<USBDeviceInfo> GetUSBDevices(){

    List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

    ManagementObjectCollection collection;

    using (var searcher = new ManagementObjectSearcher(@"Select * From 
              Win32_USBControllerDevice")) 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; 
}

using the class

public 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; }
    }
}

I wanted to make this post in case I'm missing a simpler solution to my specific problem. I'm also currently trying to reverse engineer USB View ala this question since USB view is getting the information I need somehow.

For the record I am using C# in Visual Studio 2015.

VivaLebowski
  • 113
  • 1
  • 10
  • Please post your code and what specifically is not working. Atm the question looks like `can you solve my requirements for me` – zaitsman Feb 09 '18 at 01:05
  • @zaitsman I do agree that I should have included my code and so I've incorporated it above with a clarification as to the problem I am having, and I updated the language to make it less ambiguous. – VivaLebowski Feb 12 '18 at 14:30

1 Answers1

0

I was able to implement the top level functionality I needed via a work around; I identified a part of the DeviceID string that was returned that was unique to the brand of RFID scanners that I need for my application.

I parsed the returned deviceID string and checked to see if that unique value was present, and updated my application accordingly to reflect that.

VivaLebowski
  • 113
  • 1
  • 10
  • What I believe you want to query is the 'Bus reported device description'. Still trying to figure out how. – Damian Dixon Apr 26 '18 at 11:56
  • See the answer by vromanov at https://stackoverflow.com/questions/26732291/how-to-get-bus-reported-device-description-using-c-sharp – Damian Dixon Apr 26 '18 at 12:05