我在我的 Windows 服务中使用此代码来通知插入和移除 USB 磁盘驱动器:
WqlEventQuery query = new WqlEventQuery("__InstanceOperationEvent",
"TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DriveType=2");
query.WithinInterval = TimeSpan.FromSeconds(1);
_deviceWatcher = new ManagementEventWatcher(query);
_deviceWatcher.EventArrived += new EventArrivedEventHandler(OnDeviceEventArrived);
_deviceWatcher.Start();
它可以在 XP 和 Vista 上运行,但在 XP 上,我可以听到非常明显的硬盘驱动器每秒被访问的声音。是否有另一个 WMI 查询会给我没有声音效果的事件?