Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm struggling to understand how to link the information of logical drives (C:\, D:\ etc) is on which physical drive (HDD, SATA, NVMe etc).

I'm able to pull the information separately using ManagementObject queries of both MSFT_PhysicalDisk and Win32_LogicalDisk classes but combining the two accurately is proven a real head scratcher.

A quick google threw up that I needed to use Win32_DiskDriveToDiskPartition and Win32_LogicalDiskToPartition classes but reading them just made my head hurt more. Any help would be appreciated but I'm basically after a way to show both class information side by side accurately:

ie:

C:\ is on PhysicalDrive0 (SSD)
D:\ is on PhysicalDrive1 (NVMe)
E:\ is on PhysicalDrive2 (HDD)

Cheers!

What I have tried:

I have tried piecing the information together in really janky methods (even trying to use an int list... don't ask it was a disaster) but it's not consistent.
Posted
Updated 14-Apr-22 3:29am

 
Share this answer
 
It's not straightforward. Having a WMI browser makes it much easier to jump around and look at all the objects.

Enumerate Win32_LogicalDiskToPartition.
- the Dependent field will give you a value like machinename\root\cimv2:Win32_LogicalDisk.DeviceID="C:"

Once you have the entry with the correct Dependent field, look at its Antecedent field. It will point you to the correct drive and partition ... machinename\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"

Now, enumerate Win32_DiskDriveToDiskPartition.
- find the entry whose Dependent value matches the prior Antecedent

Once you have the entry with the correct Dependent field, look at the Antecedent field. It will point you to the correct physical drive ... machinename\root\cimv2:Win32_DiskDrive.DeviceID="\\.\PHYSICALDRIVE0"

You can now enumerate Win32_DiskDrive and find the entry whose "Name" field matches that physical drive ID
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900