Use WMI ManagementEventWatcher to listen for Bluetooth devices connected/disconnected

1.9k Views Asked by At

New to WMI and am kind of feeling around in the dark a bit,

The following code detects connecting and disconnecting USB devices, but I also need to detect when a BT device is connected/disconnected (not just paired).

ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 OR EventType = 3");
watcher.EventArrived += new EventArrivedEventHandler(HardwareDeviceChange);
watcher.Query = query;
watcher.Start();

If it isn't achievable through WMI, is there another way I could go about it (hopefully avoiding 32feet solutions if at all possible).

0

There are 0 best solutions below