How to get the volume GUID

馋奶兔 提交于 2019-12-02 03:39:42

问题


I am using win32 api with C++.

I would like to know how I can get the volume GUID using a "device path".

My device looks like this:

\\?\usb#vid_04f2&pid_0111#5&39fe81e&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed}

Thanks.


回答1:


This will be the device with device instance ID usb\VID_04f2&PID_0111\5&39fe81e&0&2. That's probably a mass storage device aka disk. Now, the problem you have is that a mass storage device doesn't actually have a drive letter; it's the volume on that disk which has a drive letter. If there are two partitions, a single USB mass storage device may have two drive letters. So, there's no direct function to get the volume.

It looks like you need to enumerate the device tree rooted at usb\VID_04f2&PID_0111\5&39fe81e&0&2 to find children with device type "volume". The DEV_BROADCAST_DEVICEINTERFACE you get will have a dbcc_name field that you can pass to GetVolumeNameForVolumeMountPoint().




回答2:


Have you considered querying the WMI for it? Let me know if you need details on how to do that.



来源:https://stackoverflow.com/questions/3003810/how-to-get-the-volume-guid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!