KDecker
KDecker

Reputation: 7128

Getting all available information about connected USB devices in windows and NET

I have implemented the solution to the SO question in my code but I am looking for some more information from the connected USB devices.

I notice that in my device manager there is quite a bit more information offered. enter image description here

I am specifically interested in knowing the manufactures of the devices.

I am unsure of how I might go about determining what other properties are available from the GetPropertyValue method usage seen in SO question. I have tried some of the keywords in the last but they all report errors, so I assume that are not available properties.

Any idea how I might go about getting more information that just the DeviceID, PnpDeviceID, and Description?

EDIT: For anyone wondering here is the full list of properties and the values that I get for them. None of the devices provide more or less than what is seen here from what I can tell (possibly the cast to string?).

               Availability: 
                    Caption: USB Root Hub
                  ClassCode: 
     ConfigManagerErrorCode: 0
    ConfigManagerUserConfig: False
          CreationClassName: Win32_USBHub
   CurrentAlternateSettings: 
         CurrentConfigValue: 
                Description: USB Root Hub
                   DeviceID: USB\ROOT_HUB20\########
               ErrorCleared: 
           ErrorDescription: 
               GangSwitched: 
                InstallDate: 
              LastErrorCode: 
                       Name: USB Root Hub
            NumberOfConfigs: 
              NumberOfPorts: 
                PNPDeviceID: USB\ROOT_HUB20\4&\########&0
PowerManagementCapabilities: 
   PowerManagementSupported: 
               ProtocolCode: 
                     Status: OK
                 StatusInfo: 
               SubclassCode: 
    SystemCreationClassName: Win32_ComputerSystem
                 SystemName: ASystemName
                 USBVersion: 

And edited code from the linked SO answer, but with all of the properties.

public class USBDeviceInfo
{
    public String Availability { get; set; }
    public String Caption { get; set; }
    public String ClassCode { get; set; }
    public UInt32 ConfigManagerErrorCode { get; set; }
    public Boolean ConfigManagerUserConfig { get; set; }
    public String CreationClassName { get; set; }
    public String CurrentAlternateSettings { get; set; }
    public String CurrentConfigValue { get; set; }
    public String Description { get; set; }
    public String DeviceID { get; set; }
    public String ErrorCleared { get; set; }
    public String ErrorDescription { get; set; }
    public String GangSwitched { get; set; }
    public String InstallDate { get; set; }
    public String LastErrorCode { get; set; }
    public String Name { get; set; }
    public String NumberOfConfigs { get; set; }
    public String NumberOfPorts { get; set; }
    public String PNPDeviceID { get; set; }
    public String PowerManagementCapabilities { get; set; }
    public String PowerManagementSupported { get; set; }
    public String ProtocolCode { get; set; }
    public String Status { get; set; }
    public String StatusInfo { get; set; }
    public String SubclassCode { get; set; }
    public String SystemCreationClassName { get; set; }
    public String SystemName { get; set; }
    public String USBVersion { get; set; }
}

public static List<USBDeviceInfo> GetUSBDevices()
{
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub");
    ManagementObjectCollection collection = searcher.Get();

    List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
    foreach (var device in collection)
    {
        USBDeviceInfo deviceInfo = new USBDeviceInfo();
        deviceInfo.Availability = (String)device.GetPropertyValue("Availability");
        deviceInfo.Caption = (String)device.GetPropertyValue("Caption");
        deviceInfo.ClassCode = (String)device.GetPropertyValue("ClassCode");
        deviceInfo.ConfigManagerErrorCode = (UInt32)device.GetPropertyValue("ConfigManagerErrorCode");
        deviceInfo.ConfigManagerUserConfig = (Boolean)device.GetPropertyValue("ConfigManagerUserConfig");
        deviceInfo.CreationClassName = (String)device.GetPropertyValue("CreationClassName");
        deviceInfo.CurrentAlternateSettings = (String)device.GetPropertyValue("CurrentAlternateSettings");
        deviceInfo.CurrentConfigValue = (String)device.GetPropertyValue("CurrentConfigValue");
        deviceInfo.Description = (String)device.GetPropertyValue("Description");
        deviceInfo.DeviceID = (String)device.GetPropertyValue("DeviceID");
        deviceInfo.ErrorCleared = (String)device.GetPropertyValue("ErrorCleared");
        deviceInfo.ErrorDescription = (String)device.GetPropertyValue("ErrorDescription");
        deviceInfo.GangSwitched = (String)device.GetPropertyValue("GangSwitched");
        deviceInfo.InstallDate = (String)device.GetPropertyValue("InstallDate");
        deviceInfo.LastErrorCode = (String)device.GetPropertyValue("LastErrorCode");
        deviceInfo.Name = (String)device.GetPropertyValue("Name");
        deviceInfo.NumberOfConfigs = (String)device.GetPropertyValue("NumberOfConfigs");
        deviceInfo.NumberOfPorts = (String)device.GetPropertyValue("NumberOfPorts");
        deviceInfo.PNPDeviceID = (String)device.GetPropertyValue("PNPDeviceID");
        deviceInfo.PowerManagementCapabilities = (String)device.GetPropertyValue("PowerManagementCapabilities");
        deviceInfo.PowerManagementSupported = (String)device.GetPropertyValue("PowerManagementSupported");
        deviceInfo.ProtocolCode = (String)device.GetPropertyValue("ProtocolCode");
        deviceInfo.Status = (String)device.GetPropertyValue("Status");
        deviceInfo.StatusInfo = (String)device.GetPropertyValue("StatusInfo");
        deviceInfo.SubclassCode = (String)device.GetPropertyValue("SubclassCode");
        deviceInfo.SystemCreationClassName = (String)device.GetPropertyValue("SystemCreationClassName");
        deviceInfo.SystemName = (String)device.GetPropertyValue("SystemName");
        deviceInfo.USBVersion = (String)device.GetPropertyValue("USBVersion");
        devices.Add(deviceInfo);
    }

    collection.Dispose();
    searcher.Dispose();
    return devices;
}

Upvotes: 6

Views: 11017

Answers (1)

moarboilerplate
moarboilerplate

Reputation: 1643

The Properties collection property will contain all of the properties you can access.

https://msdn.microsoft.com/en-us/library/system.management.managementbaseobject.properties(v=vs.110).aspx

Upvotes: 2

Related Questions