Converting a drive letter to a Partition ID / Disk ID

拟墨画扇 提交于 2020-02-22 06:58:25

问题


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?



来源:https://stackoverflow.com/questions/9295668/converting-a-drive-letter-to-a-partition-id-disk-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!