Click here to Skip to main content
15,883,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900