Obtaining USB HID device information
-
I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.
-
I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.
since WMI doesnt provide what you wish, I think you're stuck with the 'wrapper class' or P/Invoke methodology - two things that may provide inspiration are :- Simple HID Library - Home[^] and HIDSharp[^]
-
I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices: ManagementObjectCollection collection; using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'")) { collection = searcher.Get(); } I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader". Is there a native .Net way to get properties such as the friendly name? I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.
This is how I get the friendly name of my USB serial devices. The friendly name is in the caption of the management objects. I get them like this:
List<string> usbSerial = new List<string>();
List<ManagementObject> listObj = new List<ManagementObject>();
try
{
string query = "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
listObj = searcher.Get().Cast<ManagementObject>().ToList();
searcher.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
usbSerial = new List<string>();
}
foreach (ManagementObject obj in listObj)
{
object captionObj = obj["Caption"]; //This will get you the friendly name.
if (captionObj != null)
{
string caption = captionObj.ToString();
if (caption.Contains("(COM")) //This is where I filter on COM-ports.
{
usbSerial.Add(caption);
}} } usbDevices = usbSerial.Distinct().OrderBy(s => s).ToArray();
Hope this can help, Groover
0200 A9 23 0202 8D 01 80 0205 00
-
since WMI doesnt provide what you wish, I think you're stuck with the 'wrapper class' or P/Invoke methodology - two things that may provide inspiration are :- Simple HID Library - Home[^] and HIDSharp[^]
Thanks Garth, and sorry to reply so late. The HIDSharp may well be the answer although I have written most of a COM wrapper anyway.