Click here to Skip to main content
11,639,861 members (60,527 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VC8.0
How to get the drive letter with physical address like "\\\\.\\PHYSICALDRIVE0"?
If we give the physical address.. It should return the drive letter assigned to that drive?? help me
Posted 2-May-11 21:54pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That is not possible because a physical drive can contain multiple drive letters.
You can however do the reverse, i.e, open a volume and get the physical drive to which it belongs.

Here is what you can do.

1. Enumerate all volumes - GetLogicalDrives.
2. Open each volume - eg. CreateFile(L"\\\\.\\C:", ...
3. Call DeviceIoControl on the handle returned by CreateFile with IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS.
Gokulnath007 at 3-May-11 4:11am
GetLogicalDrives containing only number. How to get the individual drive letter with the logical drive function. Help me regarding this.
«_Superman_» at 3-May-11 4:16am
If you read the documentation properly, you can see that the number is actually a bit field where each bit represents a drive letter. You can check this as follows -
if (dwDrives & 1) A: exists.
if (dwDrives & 2) B: exists.
if (dwDrives & 4) C: exists.

You can get this in a for loop.
Try this -

for (int i = 0; i < 32; ++i)
if (dwDrives & (1 << i))
cout << 'A' + i << " exists\n";
Olivier Levrey at 3-May-11 4:41am
Good answer. Have a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Suvendu Shekhar Giri 285
1 CPallini 177
2 F-ES Sitecore 170
3 sasanka sekhar panda 155
4 142
0 OriginalGriff 9,081
1 Sergey Alexandrovich Kryukov 8,847
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,650
4 F-ES Sitecore 2,558

Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 3 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100