检测 PnPEntity 插入
我在 C# 中使用 ManagementEventWatcher 来监视 WMI PnPEntity 事件。我的查询是这样的: “SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'”
当我插入已插入 PC 的特定设备时,会引发该事件,一切正常。但是,如果我插入相同类型的新硬件(即 PID 和 VID 相同,但有一个新的 DeviceID),则会立即引发事件,但 ConfigManagerErrorCode == 1(“设备配置不正确”) 。
然后将为设备安装驱动程序,如果我删除设备并重新插入,一切都很好。
如何检测驱动程序何时完成安装?除了 __InstanceCreationEvent 之外,还有更好的事件值得关注吗?
谢谢
I'm using a ManagementEventWatcher in C# to monitor WMI PnPEntity events. My query is this:
"SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_PnPEntity'"
When I plug in a specific device that has already been inserted into the PC the event is raised and everything is fine. However, if I insert a new piece of hardware of the same type (ie. PID and VID are the same, but a new DeviceID) the event is raised immediately, but the ConfigManagerErrorCode == 1 ("Device is not configured correctly").
The driver will then be installed for the device and if I remove the device and reinsert, everything is fine.
How do I detect when the driver has finished installing? Is there a better event to watch besides __InstanceCreationEvent?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过 __InstanceModificationEvent 相反,在配置新设备时扔掉第一个?
如果您正在查看诸如网卡或硬盘之类的特定设备,您可能需要查找不同类别的事件,因为您正在查看的事件相当广泛。
还有一些其他 P/Invoke 选项此处和这里(必须将c++转换为c#)
Have you tried __InstanceModificationEvent instead and throw out the first ones when configuring a new device?
if you are looking at a specific device like a NIC or Hard Drive you may want to look for events on a different class since the one you are looking at is rather broad.
There are also some other P/Invoke Options here and here(have to convert the c++ to c#)