我已在我的代码中实现了SO question的解决方案,但我正在寻找连接USB设备的更多信息。
我特别想知道这些设备的制造商。
我不确定如何根据SO question中的GetPropertyValue
方法用法确定可用的其他属性。我在最后尝试过一些关键字,但它们都报告错误,所以我认为这些不是可用的属性。
我知道如何获取仅有DeviceID
,PnpDeviceID
和Description
的更多信息?
编辑:对于想知道这里的人来说,我会得到完整的属性列表和值。没有任何设备提供的内容比我所知道的更多或更少(可能是演员到字符串?)。
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;
}
答案 0 :(得分:1)
Properties
集合属性将包含您可以访问的所有属性。