List All Partitions On Disk [closed]

To list disk partitions you can use WMI.

var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition");

foreach (var queryObj in searcher.Get())
{
    Console.WriteLine("-----------------------------------");
    Console.WriteLine("Win32_DiskPartition instance");
    Console.WriteLine("Name:{0}", (string)queryObj["Name"]);
    Console.WriteLine("Index:{0}", (uint)queryObj["Index"]);
    Console.WriteLine("DiskIndex:{0}", (uint)queryObj["DiskIndex"]);
    Console.WriteLine("BootPartition:{0}", (bool)queryObj["BootPartition"]);
}

Leave a Comment