One of the ways is with MSFT_Disk and BusType
(for example, I get 11 (SATA) for my disk)
How do I get the Hard Drive Controller Type in C#?
I am trying to get the equivalent of the DISKPART Location Path using C#, but I can't find a way to get the hard drive controller type.
For example:
DISKPART> detail disk
...
Location Path : PCIROOT(0)#PCI(1D04)#PCI(0000)#NVME(P00T00L00)
I tried using the WMI Win32_PnPEntity::GetDeviceProperties method to get the DEVPKEY_Device_LocationPaths property, but that property isn't implemented for my hard drives.
I also tried building it by walking the PnP Device Tree using DEVPKEY_Device_Parent and capturing DEVPKEY_Device_LocationInfo. This works except the Enumerator/Interface always shows SCSI, not NVME.
Is there another API for getting the Location Path information that has the type of hard drive controller specified? I've seen Windows Storage Management API, but that just looks like WMI.
I really don't want to go the route of DISKPART scripting and parsing text. That sounds really fragile.
Thanks,
Jonathan
-
Castorix31 83,926 Reputation points
2022-07-08T22:37:20.927+00:00
1 additional answer
Sort by: Most helpful
-
Michael Taylor 53,231 Reputation points
2022-07-08T22:04:51.357+00:00 That path you're seeing in diskpart is a combination of the path of the controller managing the drive + the drive location itself. You can get this information using WMI I believe but you'll have to do some navigating. There might be an easier way but I'd do it using WMI.
The controller's location is everything up to the last part. In your case you have a controller with a location of
PCIROOT(0)#PCI(1D04)#PCI(0000). The last part is the disk drive's location (
P00T00L00`). I haven't looked into it but I suspect this lines up with bus # 0, target Id 0 and Lun 0. You can use device manager to verify.