Search code examples
c#filesystemsdisk

How to find the disk that holds a given partition in C#?


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.


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.