Use WMI ManagementEventWatcher to listen for connected / disconnected Bluetooth devices

New to WMI, and I feel a little in the dark,

The following code detects the connection and disconnection of USB devices, but I also need to determine when the BT device is connected / disconnected (and 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 this is not possible for WMI, is there any other way I could do this (hopefully avoiding 32-bit solutions if at all possible).

+5
source share

Source: https://habr.com/ru/post/1242964/


All Articles