我知道这对你来说已经很晚了,但也许将来可以帮助某人,我有同样的问题(或多或少)我想知道设备何时被 Bitlocker 解锁,放置一个 FileSystemWatcher,我有一个想法因为不使用 continuos do while。插入设备后,使用 `WqlEventQuery insertQuery = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'");
insertWatcher = new ManagementEventWatcher(insertQuery);
insertWatcher.EventArrived += new EventArrivedEventHandler(DeviceInsertedEvent);
insertWatcher.Start();`
但是不容易知道设备何时解锁,但我看到当你解锁设备时,触发所有关于 CIM_DataFile 和 CIM_Directory 的事件 WMI,然后你可以像这样使用:` WqlEventQuery waitForBitlockerQuery = new WqlEventQuery("SELECT * From __InstanceCreationEvent WITHIN 5 where TargetInstance ISA "CIM_Directory" And TargetInstance.Drive="" + driveUnit.Name.Replace("\", "") + "" And TargetInstance.Path = ''"); //Creamos un eventto que cuando el dispotivo pueda, disparara el eventto con el direcotrio raiz, y por tanto indicando que el file system ya tiene acceso al dispositivo (isReady = true)
ManagementEventWatcher copyWatcher = new ManagementEventWatcher(waitForBitlockerQuery);
copyWatcher.EventArrived += new EventArrivedEventHandler(DeviceStatusChanged);
copyWatcher.Start();`
并使用功能 DeviceStatusChanged 在设备解锁后进行任何您想要的操作