使用 C++ 扫描本地 Windows 系统以查找连接的 USB 设备
使用 C++ 扫描本地 Windows 系统以查找连接的 USB 设备的最佳方法是什么?我需要获取供应商和产品 ID 列表,以与我的设备 ID 相匹配。如果有一种方法可以扫描特定的 VID/PID 组合,那就更好了。我的最终目标是检索 Windows 分配给设备的虚拟 COM 端口。如果有一种方法可以做到这一切,那就太棒了。一如既往,我们非常感谢例子。谢谢。
What is the best way to scan the local Windows system for attached USB devices using C++? I need to get a list of Vendor and Product IDs to match against the my device's IDs. If there is a way to scan for a specific VID/PID combination, that would be even better. My end goal is to retrieve the virtual COM port Windows has assigned to the device. If there's a way to do all that, it would be fantastic. As always, examples are much appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这几乎是您想要的 MSDN 示例:
http ://msdn.microsoft.com/en-us/library/ff558728%28VS.85%29.aspx
如果你想访问这种功能,你似乎需要WDK(我每次MSDN搜索可以想到建议这一点)。
This is pretty much an MSDN example of what you want:
http://msdn.microsoft.com/en-us/library/ff558728%28VS.85%29.aspx
It seems you'll need the WDK if you want to access this kind of functionality (every MSDN search I can think of suggests this).
我能够通过查询 WMI 来获取所需的信息来解决此问题。基本上,我能够从 Microsoft 的示例代码开始,对其进行一些修改,最后将其构建到我自己的类中,以满足我的需要。
http://msdn.microsoft.com/en -us/library/aa390423%28v=VS.85%29.aspx
此计算机系统硬件类列表也很有帮助:
http://msdn.microsoft.com/en-us/library/aa389273%28v=VS.85%29.aspx
我使用 WMI Code Creator 预览了看似有前途的类的结果。
最后我使用了以下内容:
root\CIMV2
Win32_SerialPort
PNPDeviceID
和DeviceID
I was able to resolve this by querying WMI for the needed information. Basically, I was able to start with Microsoft's example code, modify it a bit, and finally build it into my own class that does what I need.
http://msdn.microsoft.com/en-us/library/aa390423%28v=VS.85%29.aspx
This list of Computer System Hardware Classes was also helpful:
http://msdn.microsoft.com/en-us/library/aa389273%28v=VS.85%29.aspx
I used the WMI Code Creator to preview the results of what looked to be promising classes.
In the end I used the following:
root\CIMV2
Win32_SerialPort
PNPDeviceID
andDeviceID