Get drive letter on hard drive

My application is for Windows Vista and XP.

The hard drive connected to my machine has more than the hard drive. I need to get Drive Letters on the hard drive from which my system boots.

Using the GetLogicalDriveStrings function, I can get the drive letters of all the hard drives. But how can I distinguish this drive letter from the name of my bootable hard drive?

Disk structure:

disk0 (boot with this) - CDG

disk1- EFH

disk2-I J

I need to get only C, D, G.

+4
source share
1 answer

Call GetLogicalDrives to get all available drive letters.

Call GetSystemDirectory to get the disk containing the OS.

Open the volume using CreateFile ("\. \ C:", ...

Here replace C: with the drive letter returned in GetSystemDirectory.

Call DeviceIControl of the return handle with the code IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS to get the hard drive number.

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

Repeat CreateFile and DeviceIoControl on all other drives and compare the hard drive number with the one you received earlier.

+5
source

All Articles