简体   繁体   English

获取硬盘的盘符

[英]Get drive letter of Hard drive

My application is for windows Vista and XP.我的申请适用于 windows Vista 和 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.通过使用 GetLogicalDriveStrings Function 我可以获得所有硬盘的驱动器号。 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 DG disk0(以此启动)- C DG

disk1- EFH磁盘1-EFH

disk2- IJ磁盘2-IJ

I need to get the C,D,G only.我只需要获得 C,D,G。

Call GetLogicalDrives to get all the available drive letters.调用GetLogicalDrives以获取所有可用的驱动器号。

Call GetSystemDirectory to get the drive which contains the OS.调用GetSystemDirectory以获取包含操作系统的驱动器。

Open the volume using CreateFile("\.\C:", ...使用CreateFile("\.\C:", ...打开卷

Here replace C: with the drive letter returned in GetSystemDirectory.此处将 C: 替换为 GetSystemDirectory 中返回的驱动器号。

Call DeviceIControl of the returned handle with the IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS code to get the hard disk number.使用IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS代码调用返回句柄的DeviceIControl以获取硬盘编号。

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.在所有其他驱动器号上重复CreateFileDeviceIoControl ,并将硬盘号与您之前获得的硬盘号进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM