获取磁盘信息
zongdaxiao = GetHardDiskSpace("C") * 1.0 / 1024;
user = GetHardDiskFreeSpace("C") * 1.0 / 1024;
///
/// 获取指定驱动器的空间总大小(单位为B)
///
/// 只需输入代表驱动器的字母即可 (大写)
///
public long GetHardDiskSpace(string str_HardDiskName)
{
long totalSize = new long();
str_HardDiskName = str_HardDiskName + ":\\";
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
if (drive.Name == str_HardDiskName)
{
totalSize = drive.TotalSize / (1024 * 1024);
}
}
return totalSize;
}
///
/// 获取指定驱动器的剩余空间总大小(单位为B)
///
/// 只需输入代表驱动器的字母即可
///
public long GetHardDiskFreeSpace(string str_HardDiskName)
{
long freeSpace = new long();
str_HardDiskName = str_HardDiskName + ":\\";
System.IO.DriveInfo[]
C#-获取磁盘,cpu,内存信息
最新推荐文章于 2024-07-18 02:47:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)