[UWP]如何在StorageFolder和DeviceInformation之间获取CDROM设备的映射?

人气:478 发布:2022-09-22 标签: wpdevelop

问题描述

我想要维护一个可移动存储文件夹的StorageFolder数组。在设备添加/更新/删除时执行某些操作。

I wantmaintain aStorageFolder array of removable storage folders. And do something when device add/update/remove.

首先,我从KnownFolders :: RemovableDevices获取所有StorageFolder,并使用 DeviceInformation :: CreateWatcher来监听add / update / remove事件。

First, I get all StorageFolder fromKnownFolders::RemovableDevices, and useDeviceInformation::CreateWatcher to listen add/update/remove event.

如果设备是便携式的,我可以使用Windows :: Devices :: Portable :: StorageDevice :: FromId(device-> Id)来获取StorageFolder,因此已知哪个StorageFolder已更改,但如果设备是物理/虚拟CDROM,我找不到在DeviceInformation和StorageFolder之间映射的方法。

If device is portable I can useWindows::Devices::Portable::StorageDevice::FromId(device->Id) to getStorageFolder and hence known whichStorageFolder changed, but if device isphysical/virtual CDROM, I can't find a way to mapping between DeviceInformation and StorageFolder.

My Watcher AQS:

My Watcher AQS:

我还尝试为Watcher添加additionalProperties和 folder-> Properties-> RetrievePropertiesAsync,但无法找到有用的映射信息:

I also try add additionalProperties for Watcher andfolder->Properties->RetrievePropertiesAsync, but can't find useful information for mapping:

所有windows属性来自 https://docs.microsoft.com/en-us/windows/desktop/properties/props除了一些属性将导致崩溃。

all windows property fromhttps://docs.microsoft.com/en-us/windows/desktop/properties/props except some property will cause crash.

接收设备观察程序事件时,有没有办法准确确定哪个CDROM StorageFolder发生了变化?

Is any way to exactly determine which CDROM StorageFolder changed when I receive device watcher event?

谢谢。

推荐答案

好吧,似乎没有内置的API,可以知道CD-ROM的文件夹更改。您可能仍然可以使用其他一些方法来使用Win32 API来检测它。

Well, it seems there is no built-in APIs that could know the folders changes of a CD-ROM. You might still use some other ways maybe Win32 APIs to detect this.

祝你好运,

Roy

183