gpt4 book ai didi

c# - USB设备实例路径usi WMI查询c#

转载 作者:太空宇宙 更新时间:2023-11-03 15:43:52 25 4
gpt4 key购买 nike

我正在尝试使用以下代码查找 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();
}

最佳答案

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

这会起作用。你少了一个“\”。

关于c# - USB设备实例路径usi WMI查询c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29099125/

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