I am trying to put together a list which shows all LogicalDisk instances in my Computer System and the drive letters they have been associated with. Coding is in C#.
The WMI classes Win32_LogicalDiskToPartition, Win32_DiskPartition and Win32_LogicalDisk appeared to be the right data sources to get that Job done:
Win32_LogicalDiskToPartition contains the property "Antecedent" which obviously links to a "DeviceId" property of class Win32_DiskPartition
and Win32_LogicalDiskToPartition contains the property "Dependent" which obviously links to a "DeviceId" property of class Win32_LogicalDisk
And here's my problem:
The Antecedent property of Win32_LogicalDiskToPartition returns a string value like:
\\\\HOME-PC\\root\\cimv2:Win32_DiskPartition.DeviceID=\"Disk #2, Partition #0\
but I need only Disk #2, Partition #0
to match it with the DeviceId property values of class Win32_DiskPartition.
Similar Problem with the Dependent property value.
Is there a way to obtain this substring (except by hard coded string parsing)?
I am afraid a query does not help because I do also need additional information about the logical disk and the associated disk Partition. I am aware that I have to cover Extended partitions with multiple drive letters - this can be done with the StartingAddress property of the Win32_LogicalDiskToPartition instance.
This type of enumeration is usually performed using
System.Management
'sManagementObjectSearcher building the query using the WQL ASSOCIATORS OF Statement
This is one sequential path you can follow to retrieve information on drives in a system:
Objects in each class have their associated properties:
Disk Drives (MSDN)
Partition (MSDN)
Logical Disk (MSDN)