gpt4 book ai didi

c# - 在 Windows 和 NET 中获取有关连接的 USB 设备的所有可用信息

转载 作者:行者123 更新时间:2023-11-30 12:25:20 25 4
gpt4 key购买 nike

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

我注意到在我的设备管理器中提供了相当多的信息。 enter image description here

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

我不确定如何确定哪些其他属性可以从 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# - 在 Windows 和 NET 中获取有关连接的 USB 设备的所有可用信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31661180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com