Given a drive letter, how do I get the OSImage InstallTo Partition ID and Disk ID without using the registry?
Asked
Active
Viewed 2,989 times
3
-
Hi; with that Partition ID you mean 1 based index of the partition ? – TLama Feb 15 '12 at 16:56
-
See here http://technet.microsoft.com/en-us/library/ff716430.aspx. This is what I need to determine. – unixman83 Feb 15 '12 at 17:30
2 Answers
5
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
?

Ben Voigt
- 277,958
- 43
- 419
- 720
-
This doesn't look like it gives me the Disk ID # nor the partition ID. I am working with the program that installs Windows itself. The setup wants a disk id and a partition id. Not a virtual mapping. – unixman83 Feb 15 '12 at 17:47
-
1@unixman83: So the returned "target path" isn't something along the lines of `"\\.\PhysicalDisk1\Partition0"`? – Ben Voigt Feb 15 '12 at 18:03
-
Hmm, the docs said differently: `\Device\HarddiskVolume1`. I didn't try it. I guess that would work. I'll have to try it tomorrow. – unixman83 Feb 15 '12 at 22:26
-
1@unixman83: I didn't try it either. Now I see the sentence in the documentation you're talking about. I think both forms are valid, one must be a link to the other. Then we just need to figure out how to follow symbolic links in the device namespace. – Ben Voigt Feb 15 '12 at 22:32