Question

Does anyone know a way to find out programatically which physical disk holds a given partition? Manually, I can find this info using Start->Run->diskmgmt.msc , where I can see that (on my computer) that partitions C: and D: are on disk 1, E: & F: on disk 0.

This is for optimizing some file crunching operations by doing them in parallel if the files are on different physical disks.

Was it helpful?

Solution

You can obtain this information using WMI from System.Management namespace by quering Win32_DiskDrive class.

Here's basic info about WMI in .NET.

OTHER TIPS

In addition to Arul's answer, here's a link that shows how to geth the disk<->partition association using WMI from a VBS script: WMI Tasks: Disks and File Systems -> see the last example on the page.

Edit: Even better, here's a good article on WMI using C#, which just happens to also describe the exact relationships between the WMI classes needed to get the disk drive (e.g. \\\\.\\PHYSICALDRIVE0 ) that holds a logical disk (e.g. C:)

see HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices

wmic path CIM_BasedOn get * > wmic-path-CIM_BasedOn-get.txt
wmic path CIM_DiskPartition get * > wmic-path-CIM_DiskPartition-get.txt
wmic path CIM_StorageExtent get * > wmic-path-CIM_StorageExtent-get.txt

see Class: CIM_BasedOn - non enumerate hiden partition, CIM_DiskPartition -all, but not see disk label, CIM_StorageExtent - GUID, label, partition(hide too)

Are you sure the partition is associated with only one disk? It could be striped/spanned/etc across multiple physical disks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top