Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get corresponding physical disk drives of mountpoints with WMI queries?

Tags:

c#

wmi

Is there a way to retrieve a connection between a mountpoint (a volume which is mounted into the file system instead of mounted to a drive letter) and its belonging physical disk drive(s) with WMI?

For example I have got a volume mountpoint on a W2K8 server which is mounted to “C:\Data\” and the mountpoint is spreaded on the physical disk drives 2, 4, and 5 of the server (the Data Management of the Server Manager shows that) but I cannot find a way to get this to know by using WMI.

Volumes which have got a drive letter can be connected with the WMI-Classes Win32_DiskDrive --> Win32_DiskDriveToDiskPartition --> Win32_DiskPartition --> Win32_LogicalDiskToPartition --> Win32_LogicalDisk – but the problem is, that volume mountpoints aren’t listed in the class Win32_LogicalDisk, they are only listed in Win32_Volume. And I did not find a way to connect the class Win32_Volume with the class Win32_DiskDrive – there are missing some linking classes.

Does anyone know a solution?

like image 238
Thomas Avatar asked Jan 28 '10 14:01

Thomas


1 Answers

The only way I know of is using the Win32 API to help.

You open a handle to the volume using Win32_Volume.DeviceID, modified slightly. You can open a handle to the volume using the format:

\\.\Volume{[GUID]}

You then need to issue IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS on the open handle to retrieve a VOLUME_DISK_EXTENTS structure. This structure will contain a list of physical disk ids for the volume.

Using these disk ids you can query WMI on Win32_DiskDrive.Index to get the matching disk.

like image 155
AlexPi Avatar answered Nov 08 '22 06:11

AlexPi