In our .NET application we set up the following queries to detect when any USB device was added or removed:
SELECT * FROM __InstanceCreationEvent
WITHIN 0.5
WHERE TargetInstance ISA 'Win32_PnPEntity'
and
SELECT * FROM __InstanceDeletionEvent
WITHIN 0.5
WHERE TargetInstance ISA 'Win32_PnPEntity'
When we start listening to these queries we can see the process WMI Provider host
acquiring a full CPU core.
Are the above queries inefficient?
Is there a better way to detect when a USB device was attached apart from polling every x
seconds? Note that the USB devices we want to detect aren't attached as drives, they are security dongles.