Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取有关windows和NET中已连接USB设备的所有可用信息_C# - Fatal编程技术网

C# 获取有关windows和NET中已连接USB设备的所有可用信息

C# 获取有关windows和NET中已连接USB设备的所有可用信息,c#,C#,我已经在我的代码中实现了解决方案,但我正在从连接的USB设备中寻找更多信息 我注意到在我的设备管理器中提供了更多的信息。 我特别想了解这些设备的制造商 我不确定如何从中看到的GetPropertyValue方法用法中确定还有哪些其他属性可用。我在上一篇文章中尝试了一些关键字,但它们都报告了错误,所以我假设这些关键字不可用 你知道我该如何获取更多信息,而不仅仅是DeviceID,PnpDeviceID和Description 编辑:任何想知道这里是完整的属性列表以及我为它们获取的值的人。从我所能

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

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

我特别想了解这些设备的制造商

我不确定如何从中看到的
GetPropertyValue
方法用法中确定还有哪些其他属性可用。我在上一篇文章中尝试了一些关键字,但它们都报告了错误,所以我假设这些关键字不可用

你知道我该如何获取更多信息,而不仅仅是
DeviceID
PnpDeviceID
Description

编辑:任何想知道这里是完整的属性列表以及我为它们获取的值的人。从我所能看出,没有一款设备提供了比这里所看到的更多或更少的功能(可能是转换成字符串?)

并从链接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;
}
公共类USBDeviceInfo
{
公共字符串可用性{get;set;}
公共字符串标题{get;set;}
公共字符串类代码{get;set;}
公共UInt32 ConfigManager错误代码{get;set;}
公共布尔值ConfigManagerUserConfig{get;set;}
公共字符串CreationClassName{get;set;}
公共字符串CurrentAlternateSettings{get;set;}
公共字符串CurrentConfigValue{get;set;}
公共字符串说明{get;set;}
公共字符串设备ID{get;set;}
公共字符串ErrorCleared{get;set;}
公共字符串ErrorDescription{get;set;}
带开关的公共字符串{get;set;}
公共字符串InstallDate{get;set;}
公共字符串LastErrorCode{get;set;}
公共字符串名称{get;set;}
公共字符串NumberOfConfigs{get;set;}
公共字符串NumberOfPorts{get;set;}
公共字符串PNPDeviceID{get;set;}
公共字符串PowerManagementCapabilities{get;set;}
公共字符串PowerManagementSupported{get;set;}
公共字符串协议代码{get;set;}
公共字符串状态{get;set;}
公共字符串StatusInfo{get;set;}
公共字符串子代码{get;set;}
公共字符串SystemCreationClassName{get;set;}
公共字符串SystemName{get;set;}
公共字符串USBVersion{get;set;}
}
公共静态列表GetUSBDevices()
{
ManagementObjectSearcher searcher=新的ManagementObjectSearcher(@“从Win32_USBHub中选择*);
ManagementObjectCollection集合=searcher.Get();
列表设备=新列表();
foreach(集合中的var设备)
{
USBDeviceInfo deviceInfo=新的USBDeviceInfo();
deviceInfo.Availability=(字符串)device.GetPropertyValue(“Availability”);
deviceInfo.Caption=(字符串)device.GetPropertyValue(“Caption”);
deviceInfo.ClassCode=(字符串)device.GetPropertyValue(“ClassCode”);
deviceInfo.ConfigManagerErrorCode=(UInt32)device.GetPropertyValue(“ConfigManagerErrorCode”);
deviceInfo.ConfigManagerUserConfig=(布尔)device.GetPropertyValue(“ConfigManagerUserConfig”);
deviceInfo.CreationClassName=(字符串)device.GetPropertyValue(“CreationClassName”);
deviceInfo.CurrentAlternateSettings=(字符串)device.GetPropertyValue(“CurrentAlternateSettings”);
deviceInfo.CurrentConfigValue=(字符串)device.GetPropertyValue(“CurrentConfigValue”);
deviceInfo.Description=(字符串)device.GetPropertyValue(“Description”);
deviceInfo.DeviceID=(字符串)device.GetPropertyValue(“DeviceID”);
deviceInfo.ErrorCleared=(字符串)device.GetPropertyValue(“ErrorCleared”);
deviceInfo.ErrorDescription=(字符串)device.GetPropertyValue(“ErrorDescription”);
deviceInfo.GangSwitched=(字符串)device.GetPropertyValue(“GangSwitched”);
deviceInfo.InstallDate=(字符串)device.GetPropertyValue(“InstallDate”);
deviceInfo.LastErrorCode=(字符串)device.GetPropertyValue(“LastErrorCode”);
deviceInfo.Name=(字符串)device.GetPropertyValue(“名称”);
deviceInfo.NumberOfConfigs=(字符串)device.GetPropertyValue(“NumberOfConfigs”);
deviceInfo.NumberOfPorts=(字符串)device.GetPropertyValue(“NumberOfPorts”);
deviceInfo.PNPDeviceID=(字符串)device.GetPropertyValue(“PNPDeviceID”);
deviceInfo.PowerManagementCapabilities=(字符串)device.GetPropertyValue(“PowerManagementCapabilities”);
deviceInfo.PowerManagementSupported=(字符串)device.GetPropertyValue(“PowerManagementSupported”);
deviceInfo.ProtocolCode=(字符串)device.GetPropertyValue(“ProtocolCode”);
deviceInfo.Status=(字符串)device.GetPropertyValue(“状态”);
deviceInfo.StatusInfo=(字符串)device.GetPropertyValue(“StatusInfo”);
deviceInfo.SubassCode=(字符串)device.GetPropertyValue(“SubassCode”);
deviceInfo.SystemCreationClassName=(字符串)device.GetPropertyValue(“SystemCreationClassName”);
deviceInfo.SystemName=(字符串)device.GetPropertyValue(“SystemName”);
deviceInfo.USBVersion=(字符串)device.GetPropertyValue(“USBVersion”);
设备。添加(deviceInfo);
}
collection.Dispose();
searcher.Dispose();
返回装置;
}

集合属性将包含您可以访问的所有属性


InstallDate例如对我可用(可以使用USBDeview读取),但在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;
}