How can I find the drive containing a given section in C #?
Does anyone know how to programmatically determine which physical disk a given partition contains? Manually, I can find this information using Start-> Run-> diskmgmt.msc, where I see that (on my computer) the C: and D: partitions are on disk 1, E: and F: on disk 0.
This is to optimize some file crunching operations, doing them in parallel if the files are on different physical disks.
source to share
You can get this information using WMI from the System.Management namespace by querying the Win32_DiskDrive class .
source to share
In addition to Arul's answer, here's a link that shows how to map drive association and lt; -> using WMI from VBS script: WMI Tasks: Disks and File Systems -> see the last example on the page.
Edit: Better yet, here's a nice WMI article using C # that just describes the exact relationship between the WMI classes you needed to get a disk (for example \\\\.\\PHYSICALDRIVE0
) that contains a logical drive (for example C:
)
source to share
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 - do not list hiden partition, CIM_DiskPartition -all, but do not see disk label, CIM_StorageExtent - GUID, shortcut, partition (hide too)
source to share