C# UWP获取Uniqe Usb Pendrive Id

C# UWP获取Uniqe Usb Pendrive Id,c#,uwp,C#,Uwp,我对UWP应用程序有问题。我想要一个USB Pendrive的统一id。多亏了它,我将能够区分我应该向哪个USB Pendrive发送文件。当然,我可以从KnownFolders.RemovabelDevices获取FolderRelitiveId,但该值不是唯一的。我想我需要GUID、VID或PID。有没有办法获取所有USB存储设备及其所有信息?根据您的要求,您可以使用API获取便携式存储设备。有关更多详细信息,请参考场景2 handlerAdded = new TypedEventHandl

我对UWP应用程序有问题。我想要一个USB Pendrive的统一id。多亏了它,我将能够区分我应该向哪个USB Pendrive发送文件。当然,我可以从KnownFolders.RemovabelDevices获取FolderRelitiveId,但该值不是唯一的。我想我需要GUID、VID或PID。有没有办法获取所有USB存储设备及其所有信息?

根据您的要求,您可以使用API获取便携式存储设备。有关更多详细信息,请参考场景2

handlerAdded = new TypedEventHandler<DeviceWatcher, DeviceInformation>(async (watcher, deviceInfo) =>
{
    // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
    await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
    {
        ResultCollection.Add(new DeviceInformationDisplay(deviceInfo));

        rootPage.NotifyUser(
            String.Format("{0} devices found.", ResultCollection.Count),
            NotifyType.StatusMessage);
    });
});
handleraded=new-TypedEventHandler(异步(观察者,设备信息)=>
{
//由于集合已绑定到UI元素,因此需要在UI线程上更新集合。
等待rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low,()=>
{
添加(新设备信息显示(设备信息));
rootPage.NotifyUser(
String.Format(“{0}已找到设备。”,ResultCollection.Count),
NotifyType.StatusMessage);
});
});

然后,您可以从
deviceInfo
对象获取唯一的id。

根据您的要求,您可以使用API获取便携式存储设备。有关更多详细信息,请参考场景2

handlerAdded = new TypedEventHandler<DeviceWatcher, DeviceInformation>(async (watcher, deviceInfo) =>
{
    // Since we have the collection databound to a UI element, we need to update the collection on the UI thread.
    await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
    {
        ResultCollection.Add(new DeviceInformationDisplay(deviceInfo));

        rootPage.NotifyUser(
            String.Format("{0} devices found.", ResultCollection.Count),
            NotifyType.StatusMessage);
    });
});
handleraded=new-TypedEventHandler(异步(观察者,设备信息)=>
{
//由于集合已绑定到UI元素,因此需要在UI线程上更新集合。
等待rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Low,()=>
{
添加(新设备信息显示(设备信息));
rootPage.NotifyUser(
String.Format(“{0}已找到设备。”,ResultCollection.Count),
NotifyType.StatusMessage);
});
});

然后您可以从
deviceInfo
对象中获得唯一的id。

这个问题的结果非常简单。您可以使用DeviceInformation ID初始化StorageDevice。然后您可以从中获取StorageFolder。不要忘记为UWP添加对Windows桌面扩展的引用。

此问题的结果非常简单。您可以使用DeviceInformation ID初始化StorageDevice。然后您可以从中获取StorageFolder。不要忘记为UWP添加参考:Windows桌面扩展。

谢谢您的帮助。我可以得到唯一的id,但我有其他问题。使用KnownFolder.RemovableDevices,我可以获取设备的真实名称,但无法获取设备信息中的属性。有没有办法从DeviceInfromation获取此设备的路径?我可以从DeviceInformation获取任何特殊属性吗?
DeviceInfromation
不提供便携式存储设备的路径属性,但您可以获取具有DeviceInformation id的
RemovableDevices
,然后获取路径属性。我不明白您的答案。您是否正在考虑检索文件夹的其他属性?我找到了使用StorageDevice的解决方案。我可以通过从StorageDevice by DeviceInformation Id获取文件夹来获取USB存储文件夹(对于有问题的人,请添加名为“UWP的Windows桌面扩展”的参考)。也就是说,我想说的是通过设备信息Id从StorageDevice获取文件夹。如果您有解决方案,请发布您的答案,您可以将自己标记为方便稍后访问此线程的人。感谢您的帮助。我可以得到唯一的id,但我有其他问题。使用KnownFolder.RemovableDevices,我可以获取设备的真实名称,但无法获取设备信息中的属性。有没有办法从DeviceInfromation获取此设备的路径?我可以从DeviceInformation获取任何特殊属性吗?
DeviceInfromation
不提供便携式存储设备的路径属性,但您可以获取具有DeviceInformation id的
RemovableDevices
,然后获取路径属性。我不明白您的答案。您是否正在考虑检索文件夹的其他属性?我找到了使用StorageDevice的解决方案。我可以通过从StorageDevice by DeviceInformation Id获取文件夹来获取USB存储文件夹(对于有问题的人,请添加名为“UWP的Windows桌面扩展”的参考)。也就是说,我想说的是通过设备信息Id从StorageDevice获取文件夹。如果您有解决方案,请发布您的答案,您可以将自己标记为方便稍后访问此线程的人。