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

}

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website