ManagementClass devs = new ManagementClass(@"Win32_Diskdrive");
ManagementObjectCollection moc = devs.GetInstances();
foreach (ManagementObject mo in moc)
{
UInt32 physicalDiskNumber = (UInt32)mo["Index"];
UInt64 diskSize = (UInt64)mo["Size"];
foreach (ManagementObject b in mo.GetRelated("Win32_DiskPartition"))
{
//b["Name"] gives something like "Disk #0, Partition #0"
string[] elems = b["Name"].ToString().Split(',');
int partitionNumber = Int32.Parse(elems[1].Replace("Partition #", "").Trim());
ulong size = (ulong) b["Size"];
}
}
This is my code that retrieves all partitions on all disks. However, it does not retrieve Microsoft Reserved Partitions. I want to retrieve ALL partitions on disk, including MSR partitions. How can I accomplish this in C#?