我玩过 WqlEventQuery 来识别插入 USB 的设备
var query = new WqlEventQuery();
query.EventClassName = "__InstanceOperationEvent";
query.WithinInterval = new TimeSpan(0, 0, 2);
query.Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'";
using (var watcher = new ManagementEventWatcher(query))
{
watcher.EventArrived += WatcherEvent;
watcher.Start();
... Wait condition ...
watcher.Stop();
}
然后我尝试在观察者事件处理程序中查找设备属性
foreach (var mbo in e.NewEvent.Properties.Cast<PropertyData>().Where(i => i.Value != null && i.Value is ManagementBaseObject).Select(pdData => (ManagementBaseObject)pdData.Value).Where(mbo => mbo != null))
{
if (mbo.ClassPath.ClassName == "Win32_USBControllerDevice")
{
foreach (var prop in mbo.SystemProperties)
{
... look for the property content
}
}
}
但找不到可以提取有关插入设备的信息的地方。因此,当我通过 USB 端口插入手机时。我想从特定的生产商那里提取表明特定型号的电话的信息,依此类推。
我是否正在做正确的事情来获取这些信息?在这方面我应该尝试不同或更有效的方法吗?
谢谢!