static void GetSysDiskSpace() { string sysDrice = Environment.GetEnvironmentVariable("systemdrive"); using (ManagementClass DiskClass = new ManagementClass(@"Win32_Diskdrive")) { using (ManagementObjectCollection Moc = DiskClass.GetInstances()) { foreach (ManagementObject Mo_Disk in Moc) { foreach (ManagementObject Mo_Partition in Mo_Disk.GetRelated("Win32_DiskPartition")) { long size = 0; bool isEx = false; foreach (ManagementBaseObject Mbo_Logical in Mo_Partition.GetRelated("Win32_LogicalDisk")) { size += Convert.ToInt64(Mbo_Logical["Size"]); string name = Mbo_Logical["Name"].ToString(); if (sysDrice.Equals(name)) { isEx = true; } } if (isEx) { Console.WriteLine("{0}", size); return; } } } } } }