Get The Total Size of Multiple HDD

The following code will show you how it can be retrieved the total size of multiple HDDs installed on your system. Using the same method you can do this for available free space. I've also converted bytes to GB as the value is retrieved in bytes. For this you can use the Size property from the Win32_DiskDrive class:

private static String getHDDsize()
        {
            Double sum = 0;

            ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From Win32_DiskDrive");

            foreach (ManagementObject item in mos.Get())
            {
                double HDD_size = Convert.ToDouble(item["Size"]);
                sum += HDD_size;
            }

            return Convert.ToString(Math.Round(sum / 1073741824, 2)) + " GB";
        }

1 comment:

  1. nice..but how to get full volume like 500 GB HDD..?

    ReplyDelete