问题
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