0
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#?

MyGGaN
  • 1,766
  • 3
  • 30
  • 41
miara
  • 847
  • 1
  • 6
  • 12
  • Check this out https://stackoverflow.com/questions/30988603/how-to-access-hidden-partitions-volumes – Srikanth Jul 26 '17 at 03:14
  • That didn't quite work. Ended up writing a C++ DLL to call IOCTLs and send info to C# code – miara Jul 27 '17 at 21:06

0 Answers0