获取硬盘驱动器号 [英] Get drive letter of Hard drive
问题描述
大家好,
我的应用程序适用于Windows Vista和XP.
与我的机器相连的硬盘驱动器上还有更多内容.我需要获取从中引导系统的硬盘驱动器的驱动器号.
通过使用GetLogicalDriveStrings函数,我可以获得所有硬盘的驱动器号.但是,如何区分这个特殊的驱动器号是引导硬盘的分区名称?
磁盘的结构为:
disk0(以此引导)-CDG
disk1- EFH
disk2- IJ
我只需要获取C,D,G.
感谢Madan
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
推荐答案
调用GetLogicalDrives
获取所有可用的驱动器号.
调用GetSystemDirectory
获得包含操作系统的驱动器.
使用CreateFile("\\.\C:", ...
打开卷,在此将C:替换为GetSystemDirectory
中返回的驱动器号.
使用IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
代码调用返回的句柄的DeviceIControl
以获取硬盘号.
现在您知道包含操作系统的驱动器的硬盘号.
在所有其他驱动器号上重复CreateFile
和DeviceIoControl
并将硬盘号与硬盘驱动器号进行比较.你早一点的.
CallGetLogicalDrives
to get all the available drive letters.
CallGetSystemDirectory
to get the drive which contains the OS.
Open the volume usingCreateFile("\\.\C:", ...
Here replace C: with the drive letter returned inGetSystemDirectory
.
CallDeviceIControl
of the returned handle with theIOCTL_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 theCreateFile
andDeviceIoControl
on all the other drive letters and compare the hard disk number with the one you got earlier.
这篇关于获取硬盘驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!