How can I list all the logical volumes on disk? I want the volume name to be suitable for opening with CreateFile .
What have you tried?
I used the FindFirstVolume / FindNextVolume to list the volumes. It returns a list of names, such as:
\\?\Volume{0b777018-3313-11e2-8ccd-806e6f6e6963}\\\?\Volume{0b777019-3313-11e2-8ccd-806e6f6e6963}\\\?\Volume{758a2cf2-cf3a-11e4-8dce-c86000d0b92a}\\\?\Volume{4f81d34b-34f4-11e2-9f6e-c86000d0b92a}\
But none of these volume names are valid volume names. That is, none of these names can be passed to CreateFile to open the volume:
0x00000003 (The system cannot find the path specified)
The question is, how can I convert the thing returned by FindFirstVolume to a volume name?
But the real question is: how do I list volumes in the first place?
Why not just use \\.\C: :?
I did not ask how hard to encode the volume name; I asked how to list the names of volumes.
In addition, not every volume has a drive letter, for example:
\\?\Volume{0b777019-3313-11e2-8ccd-806e6f6e6963}\ ==> \\.\C:\\?\Volume{758a2cf2-cf3a-11e4-8dce-c86000d0b92a}\ ==> \\.\D:\\?\Volume{0b777018-3313-11e2-8ccd-806e6f6e6963}\ ==> reserved volume of the system without a drive letter\\?\Volume{4f81d34b-34f4-11e2-9f6e-c86000d0b92a}\ ==> the CD installed in the folder
I swear there is an API for listing volumes.
GetLogicalDriveStrings
The problem with GetLogicalDriveStrings is that it only returns logical drives:
not volumes . In my case, it skips two volumes:
- System reserved
- D: \ CDROM
for FindFirstVolume do the right thing.
Reading bonuses
source share