Given a drive letter, how do I get the OSImage InstallTo Partition ID and Disk ID without using the registry?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
is also useful, MSDN Example, and this stackoverflow answer.
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.
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
.
回答2:
Have you tried simply calling QueryDosDevice
?