将驱动器号转换为分区 ID/磁盘 ID [英] Converting a drive letter to a Partition ID / Disk ID
问题描述
给定驱动器盘符,我如何获取 OSImage InstallTo 分区 ID 和 磁盘 ID 而不使用注册表?
Given a drive letter, how do I get the OSImage InstallTo Partition ID and Disk ID without using the registry?
推荐答案
WMI
类 Win32_DiskPartition
正是我所需要的.现在来弄清楚如何使用 WMI
从驱动器号中获取此信息.
The WMI
class Win32_DiskPartition
is what I need. Now to figure out how to use WMI
to get this information from a drive letter.
Win32_LogicalDisk
也很有用,MSDN 示例,以及此 stackoverflow 答案.
更新:嗯,这行不通!无论如何不在 Windows 安装程序中(Windows PE 中缺少 WMI!!) 所以我使用了另一个答案 QueryDosDevice
(例如 \\.\PhysicalDisk1\Partition0
)并破解它一起.这让微软很不爽,在你的安装程序中接受一个该死的路径.
Update: Hmm, this doesn't work! Not in the Windows Installer anyway (WMI is missing from Windows PE!!) so I am using the other answer QueryDosDevice
(e.g. \\.\PhysicalDisk1\Partition0
) and hacking it together. This sucks Microsoft, accept a damn path in your installer.
答案: IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
用于获取磁盘 ID
.DeviceIoControl IOCTL_DISK_GET_PARTITION_INFO_EX
(感谢 TLama)为我获取Partition ID
.
Answer: IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
works to get the Disk ID
. And DeviceIoControl IOCTL_DISK_GET_PARTITION_INFO_EX
(thanks TLama) gets me the Partition ID
.
这篇关于将驱动器号转换为分区 ID/磁盘 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!