我可以捕获USB设备连接事件,使用Win32_DeviceChangeEvent,但只允许查看3个属性。
但我不明白如何获取有关此设备的全部信息。具体来说,它的端口和集线器、VirtualHubAdress名称等。
也许我可以使用类似这样的东西来做。
class Win32_DeviceChangeEvent : __ExtrinsicEvent
{
uint8 SECURITY_DESCRIPTOR[];
uint64 TIME_CREATED;
uint16 EventType;
};
但我不明白如何获取有关此设备的全部信息。具体来说,它的端口和集线器、VirtualHubAdress名称等。
public enum EventType
{
Inserted = 2,
Removed = 3
}
public static void RegisterUsbDeviceNotification()
{
var watcher = new ManagementEventWatcher();
var query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
//watcher.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
watcher.EventArrived += (s, e) =>
{
//here is im need to get info about this device
EventType eventType = (EventType)(Convert.ToInt16(e.NewEvent.Properties["EventType"].Value));
};
watcher.Query = query;
watcher.Start();
}
也许我可以使用类似这样的东西来做。
[DllImport("UseFull.dll")]
private IntpPtr GetAllinfo(params);