C# 获取系统盘所在磁盘空间大小

 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;
                            }
                        }
                    }
                }
            }
        }

  

C# 获取系统盘所在磁盘空间大小

上一篇:Illustrator(AI)CS3模仿绘制矢量效果的荷花插画实例教程


下一篇:[20151023]linux下删除数据文件的恢复细节2