views:

739

answers:

3

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.

+3  A: 

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

Here's basic info about WMI in .NET.

arul
A: 

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

Joel Coehoorn
Yeah, I'm aware of the possibility. I'm taking it one step at a time :)
Cristi Diaconescu
+1  A: 

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:)

Cristi Diaconescu