zoukankan      html  css  js  c++  java
  • C#获取本地磁盘信息【转载】

     

     

    直接上干货简单易懂

    //磁盘监控(远程/本地)
    //需要引用System.Management.dll
    public class RemoteMonitoring
    {
    private static string strMsg = "";
    private static long freesize = 0, size = 0;
    private static long gb = 1024 * 1024 * 1024;//GB,这里可以自己定义获取是MB还是GB

    public static string ThreadDisk()
    {
    strMsg = "";
    string strHostName = Dns.GetHostName(); //取得本机的主机名
    IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
    string localip = ipEntry.AddressList[0].ToString(); //假设本地主机为单网卡,取得第一个IP
    try
    {
    long minsize = long.Parse(CommonField.minsize);
    if (CommonField.ip == localip)
    {
    #region 本机
    foreach (DriveInfo drive in DriveInfo.GetDrives())
    {
    if (drive.DriveType == DriveType.Fixed)
    {
    freesize = drive.TotalFreeSpace / gb;
    size = drive.TotalSize / gb;
    if (freesize <= minsize)
    {
    strMsg += localip + "磁盘" + drive.Name + "的可用空间为" + freesize + "GB,请及时清理!" + System.Environment.NewLine;
    }
    strMsg += "磁盘" + drive.Name + "的总空间:" + size + "MB!" + "可用空间:" + freesize + "GB!" + System.Environment.NewLine;
    }
    }
    #endregion
    }
    return strMsg;
    }
    catch (Exception ex)
    {
    strMsg = ex.Message;
    }
    return strMsg;
    }

    }

  • 相关阅读:
    clion打断点不生效
    PHP加密解密
    细说MySQL表操作
    细说MySQL数据库操作
    终端(命令行)连接MySQL
    MySQL结构
    求1!+(1!+3!)+(1!+3!+5!)+...+(1!+3!+5!+7!+9!)的值
    react 生命周期
    React TS 组件 Demo
    react-redux 实现原理
  • 原文地址:https://www.cnblogs.com/alphaxz/p/9340419.html
Copyright © 2011-2022 走看看