【问题标题】:USB device Instace path usi WMI query c#USB设备实例路径usi WMI查询c#
【发布时间】:2015-03-17 12:29:25
【问题描述】:

我正在尝试使用以下代码查找 USB 设备实例路径,并且总是收到有关错误查询的错误。谁能帮帮我?

string strDeviceName = "USB\\VID_";
string Win32_PnPEntity = "Select * From Win32_PnPEntity Where DeviceID like '%" + strDeviceName + "%'" ;
ManagementObjectSearcher mySearcher = new ManagementObjectSearcher(Win32_PnPEntity);
foreach (ManagementObject mobj in mySearcher.Get())
{
    string strDeviceID = mobj["DeviceID"].ToString();
}

【问题讨论】:

  • 字符串 strDeviceName = "USB\\VID_"; string Win32_PnPEntity = "Select * From Win32_PnPEntity where DeviceID like '%" + strDeviceName + "%'" ; ManagementObjectSearcher mySearcher = new ManagementObjectSearcher(Win32_PnPEntity); foreach (ManagementObject mobj in mySearcher.Get()) { string strDeviceID = mobj["DeviceID"].ToString();
  • 您可以编辑自己的问题

标签: c# usb wmi


【解决方案1】:

string strDeviceName = "USB\\\\VID_";string strDeviceName = @"USB\\VID_";

这会奏效。你少了一个“\”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2013-10-07
    • 2013-03-29
    • 2023-04-06
    • 2016-01-13
    相关资源
    最近更新 更多