Click here to Skip to main content
16,017,502 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi all,

My application is for windows Vista and XP.
There are more than on Hard drive connected to my machine. I need to get Drive Letters of the Hard drive from which my system is booting.
By using GetLogicalDriveStrings Function I can get the drive letters of all Hard drives. But how can I differentiate that this particular drive letter is the partition name of my booting Hard drive?

The structure of disks are:

disk0(Booting with this)- C D G

disk1- E F H

disk2- I J

I need to get the C,D,G only.



Thanks
Madan
Posted

1 solution

Call GetLogicalDrives to get all the available drive letters.
Call GetSystemDirectory to get the drive which contains the OS.

Open the volume using CreateFile("\\.\C:", ...
Here replace C: with the drive letter returned in GetSystemDirectory.

Call DeviceIControl of the returned handle with the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS code to get the hard disk number.

Now you know the hard disk number of the drive containing the OS.

Repeat the CreateFile and DeviceIoControl on all the other drive letters and compare the hard disk number with the one you got earlier.

 
Share this answer
 


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