获取硬盘驱动器盘符
我的应用程序适用于 Windows Vista 和 XP。
有多个硬盘驱动器连接到我的机器。我需要获取系统启动时所用硬盘的驱动器盘符。
通过使用 GetLogicalDriveStrings 函数,我可以获得所有硬盘驱动器的驱动器号。但是我如何区分这个特定的驱动器号是我的启动硬盘的分区名称?
磁盘的结构是:
disk0(以此引导)- CDG
disk1- EFH
disk2- IJ
我只需要获取C,D,G。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用GetLogicalDrives获取所有可用的驱动器号。
调用GetSystemDirectory获取包含操作系统的驱动器。
使用 CreateFile("\.\C:", ... 打开卷
,此处将 C: 替换为 GetSystemDirectory 中返回的驱动器号。
调用返回句柄的 DeviceIControl IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS 代码获取硬盘编号
现在您知道包含操作系统的驱动器的硬盘编号,
然后重复 CreateFile 。 DeviceIoControl 在所有其他驱动器号上,并将硬盘编号与您之前获得的硬盘编号进行比较。
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.