获取硬盘驱动器号 [英] Get drive letter of Hard drive

查看:145
本文介绍了获取硬盘驱动器号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的应用程序适用于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以获取硬盘号.

现在您知道包含操作系统的驱动器的硬盘号.

在所有其他驱动器号上重复CreateFileDeviceIoControl并将硬盘号与硬盘驱动器号进行比较.你早一点的.

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.


这篇关于获取硬盘驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆