因为公司有多个服务器,要检查磁盘的使用情况确定程序放哪个服务器和清理垃圾,所以写个小程序帮忙检查。

效果图:

后台代码:

 private void btnCheck_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
if (rbtnRemote.Checked)
{
//远程
RemoteDisk();
}
else
{
//本地
LocalDisk();
}
}
//查看本地
private void LocalDisk()
{
WqlObjectQuery wmiquery = new WqlObjectQuery("select * from Win32_LogiCalDisk");
ManagementObjectSearcher wmifind = new ManagementObjectSearcher(wmiquery);
//显示
ShowInfo(wmifind);
} //远程
private void RemoteDisk()
{
if (cbIP.Text == "" | cbUserName.Text == "" | txtPwd.Text == "")
{
MessageBox.Show("请把信息补充完整!");
return;
}
string ip = cbIP.Text;
string username = cbUserName.Text;
string password = txtPwd.Text;
ConnectionOptions conn = new ConnectionOptions();
conn.Username = username;
conn.Password = password;
conn.Timeout = new TimeSpan(,,,);//连接时间 //ManagementScope 的服务器和命名空间。
string path = string.Format(@"\\{0}\root\cimv2", ip);
//表示管理操作的范围(命名空间),使用指定选项初始化ManagementScope 类的、表示指定范围路径的新实例。
ManagementScope scope = new ManagementScope(path, conn);
scope.Connect();
//查询
string strQuery = "select * from Win32_LogicalDisk ";
ObjectQuery query = new ObjectQuery(strQuery);
//查询ManagementObjectCollection返回结果集
ManagementObjectSearcher wmifind = new ManagementObjectSearcher(scope, query);
ShowInfo(wmifind);
} #region 显示磁盘信息
private void ShowInfo(ManagementObjectSearcher wmifind)
{
long gb = * * ;
string type = "";
string str = "";
double freePath = 0d;
foreach (var mobj in wmifind.Get())
{
type = mobj["Description"].ToString();
//判断是否是本机固盘
if (type == "Local Fixed Disk")
{
str = " 磁盘名称:" + mobj["Name"].ToString();
freePath = Math.Round(Convert.ToDouble(mobj["FreeSpace"]) / gb, );
str += " 可用空间:" + freePath+ "G";
str += " 实际大小:" + Math.Round(Convert.ToDouble(mobj["Size"].ToString()) / gb, ) + "G";
if (freePath < )
{
str += " ----请尽快清理!";
}
listBox1.Items.Add(str);
}
}
}
#endregion private void rbtnLocal_CheckedChanged(object sender, EventArgs e)
{
//本地选中
if (rbtnLocal.Checked == true)
{
cbIP.Enabled = false;
cbUserName.Enabled = false;
txtPwd.Enabled = false;
}
} private void rbtnRemote_CheckedChanged(object sender, EventArgs e)
{
if (rbtnRemote.Checked == true)
{
cbIP.Enabled = true;
cbUserName.Enabled = true;
txtPwd.Enabled = true;
}
}

C#获取本地或远程磁盘使用信息的更多相关文章

  1. 获取本地IP和mac等信息

    1获取mac protected string getHostMacName() { string mac = ""; ManagementClass mc; mc = new M ...

  2. java sigar获取本地信息以及org.hyperic.sigar.SigarException: The device is not ready报错解决

    window下,使用java sigar 获取磁盘使用率,cpu使用率以及内存使用情况等信息时. 一:首先需要下载jar包和相关文件 sigar-1.6.4.zip 如果想了解更多可以去 sigar官 ...

  3. 获取本地IP地址信息

    2012-06-05    /// <summary>         /// 获取本地IP地址信息         /// </summary>         void G ...

  4. python获取esxi的磁盘使用率信息

    #!/usr/bin/python3 #coding:utf-8 #Author: ziming """ 只用于模拟开发功能测试 """ f ...

  5. Android 获取本地外网IP、内网IP、计算机名等信息

    一.获取本地外网IP public static String GetNetIp() { URL infoUrl = null; InputStream inStream = null; try { ...

  6. 通过wmi获取本地硬件信息的一些疑问。

    通过wmi获取本地硬件信息的一些疑问. http://bbs.csdn.net/topics/391017789 http://blog.csdn.net/xcntime/article/detail ...

  7. Microsoft Azure Web Sites应用与实践【2】—— 通过本地IIS 远程管理Microsoft Azure Web Site

    Microsoft Azure Web Sites应用与实践 系列: [1]—— 打造你的第一个Microsoft Azure Website [2]—— 通过本地IIS 远程管理Microsoft ...

  8. JavaScript获取客户端计算机硬件及系统等信息的方法

    JavaScript获取客户端计算机硬件及系统等信息的方法 JavaScript 获取客户端计算机硬件及系统信息 通过WMI来实现获取客户端计算机硬件及系统信息: function getSysInf ...

  9. IOS本地,APNS远程推送(具体过程)

    添加本地推送 ///本地添加 -(void)addLocalPushNotification:(UIButton*)sender; { NSLog(@"%s",__FUNCTION ...

随机推荐

  1. 外包采用Gradle生成多套app打包

    目的:可修改app名称.icon.包名.接口地址及其它 一.      修改基本配置(包名.版本号等) 配置module下的build.gradle 添加productFlavors例如: produ ...

  2. Discuz! 的编码规范

    http://open.discuz.net/?ac=document&page=dev_coderule 前言 本规范由编程原则组成,融合并提炼了开发人员长时间积累下来的成熟经验,意在帮助形 ...

  3. 【News】SpagoBI中国官方微信对外发布

    爱数据,爱分析,爱达比 致力于国际优秀开源BI应用在中国的普及推广,用数据开启中小企业智慧之门: 扫描上图二维码,关注SpagoBI中国官方微信,2015年8月18日将在腾讯课堂.百度传课.网易云课堂 ...

  4. 解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题(l转)

    同时在工程中引入了多个第三方jar包,导致调用的方法数超过了android设定的65536个(DEX 64K problem),进而导致dex无法生成,也就无法生成APK文件. 解决办法如下: 1.谷 ...

  5. iOS开发——项目实战总结&带你看看Objective-C的精髓

    带你看看Objective-C的精髓 1:接口与实现 @interface...@end @implementation...@end @class 接口(头文件) 实现文件 向前引用 注:类别通过增 ...

  6. Xcode7.x中安装Alcatraz

    将Xcode升级了,发现Alcatraz失效了: xcode7.x安装插件命令:curl -fsSL https://raw.github.com/supermarin/Alcatraz/master ...

  7. js-2

    var myarray= new Array(); var myarray= new Array(8); var myarray= new Array(66,80,60,59,70); var mya ...

  8. 查询反模式 - GroupBy、HAVING的理解

    为了最简单地说明问题,我特地设计了一张这样的表. 一.GROUP BY单值规则 规则1:单值规则,跟在SELECT后面的列表,对于每个分组来说,必须返回且仅仅返回一个值. 典型的表现就是跟在SELEC ...

  9. 转载 -- 如何判断Javascript对象是否存在

    http://www.ruanyifeng.com/blog/2011/05/how_to_judge_the_existence_of_a_global_object_in_javascript.h ...

  10. android手机出现sqlite3 not found的解决方法

    解决方法如下: 1.如果/system目录为不可读写的,需要挂载为读写: C:\Users\easteq>adb shell root@android:/ # mount -o remount, ...