Click here to Skip to main content
13,002,343 members (79,161 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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_» 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 3 May 2011
Copyright © CodeProject, 1999-2017
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