I am trying to track the insertion of USB devices and the insertion of CD / DVD in Windows using WMI. However , when I use the Win32_LogicalDisk class to track these events, the floppy starts to make noise.
My queries are similar to below. The first is for USB, and the second is for CD.
q = gcnew WqlEventQuery(); q->EventClassName = "__InstanceCreationEvent"; q->WithinInterval = TimeSpan(0, 0, 3); q->Condition = "TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 2 and TargetInstance.DeviceID <> 'A:' and TargetInstance.DeviceID <> 'B:'"; w = gcnew ManagementEventWatcher(scope, q); w->EventArrived += gcnew EventArrivedEventHandler(USBAdded); w->Start();
q = gcnew WqlEventQuery(); q->EventClassName = "__InstanceModificationEvent"; q->WithinInterval = TimeSpan(0, 0, 3); q->Condition = "TargetInstance ISA 'Win32_LogicalDisk' and TargetInstance.DriveType = 5 and TargetInstance.DeviceID <> 'A:' and TargetInstance.DeviceID <> 'B:'"; w = gcnew ManagementEventWatcher(scope, q); w->EventArrived += gcnew EventArrivedEventHandler(LogicalInserted); w->Start();
In fact, it does not create noise in all versions. Any idea would be greatly appreciated.
source share