【问题标题】:Getting all available information about connected USB devices in windows and NET获取有关在 windows 和 NET 中连接的 USB 设备的所有可用信息
【发布时间】:2015-07-27 19:00:48
【问题描述】:

我已经在我的代码中实现了SO question 的解决方案,但我正在从连接的 USB 设备中寻找更多信息。

我注意到在我的设备管理器中提供了更多信息。

我对了解这些设备的制造商特别感兴趣。

我不确定如何从SO question 中看到的GetPropertyValue 方法使用中确定哪些其他属性可用。我在最后尝试了一些关键字,但它们都报告错误,所以我假设它们不是可用的属性。

知道如何获取更多信息,而不仅仅是DeviceIDPnpDeviceIDDescription

编辑:对于任何想知道这里的人来说,这里是属性的完整列表以及我为它们获得的值。据我所知(可能是转换为字符串?)。

               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: 

并从链接的 SO 答案中编辑了代码,但具有所有属性。

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

【问题讨论】:

    标签: c#


    【解决方案1】:

    【讨论】:

    • 例如 InstallDate 可供我使用(可以使用 USBDeview 读取),但在 Properties 集合中为空。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多