我正在尝试使用 WMI 在 Windows 上跟踪 USB 设备插入和 CD/DVD 插入。但是,当我使用 Win32_LogicalDisk 类来跟踪这些事件时,软盘开始发出噪音。
我的查询如下。第一个用于 USB,第二个用于 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();
实际上,它不会在所有版本上产生噪音。任何想法将不胜感激。