远程与本地的磁盘使用情况与进程监控
2013-09-02 15:49
405 查看
本地磁盘:
//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 * 1024);
// }
//}
//return totalSize;
远程监控磁盘使用情况:
long mb = 1048576;
//1024x1024
//设定生成的WMI所需的所有设置
System.Management.ConnectionOptions Conn = new ConnectionOptions();
//设定用于WMI连接操作的用户名
Conn.Username = "Administrator";
//设定用户的口令
Conn.Password = "ohmydear";
//设定用于执行WMI操作的范围
System.Management.ManagementScope Ms = new ManagementScope("\\\\" + "10.0.0.254" + "\\root\\cimv2", Conn);
try
{
//连接到实际操作的WMI范围
Ms.Connect();
//设定通过WMI要查询的内容
ObjectQuery Query = new ObjectQuery("select FreeSpace ,Size ,Name from Win32_LogicalDisk where DriveType=3");
//WQL语句,设定的WMI查询内容和WMI的操作范围,检索WMI对象集合
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Ms, Query);
//异步调用WMI查询
ManagementObjectCollection ReturnCollection = Searcher.Get();
double free = 0;
double use = 0;
double total = 0;
//listBox1.Items.Clear ( ) ;
//通过对产生的WMI的实例集合进行检索,获得硬盘信息
foreach (ManagementObject Return in ReturnCollection)
{
if (Return["Name"].ToString() == "D:")
{
//获得硬盘的可用空间
free = Convert.ToInt64(Return["FreeSpace"]) / mb;
//获得硬盘的已用空间
use = (Convert.ToInt64(Return["Size"]) - Convert.ToInt64(Return["FreeSpace"])) / mb;
//获得硬盘的合计空间
total = Convert.ToInt64(Return["Size"]) / mb;
}
}
}
catch (Exception ee)
{
//MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ,"出现错误!" ) ;
}
//查看本地进程运行状况
foreach (Process[] thisproc in System.Diagnostics.Process.GetProcesses("10.0.0.147"))
{
if (thisproc.ProcessName == "Foxmail")
{
result = true;
break;
}
else if (thisproc.ProcessName == "QQ")
{
result = true;
}
else
{
result = false;
}
}
//远程查看计算机的服务运行状况
public bool FindProcess(string ProcessName)
{
bool result = false;
System.Management.ConnectionOptions Conn = new ConnectionOptions();
//设定用于WMI连接操作的用户名
Conn.Username = "Administrator";
//设定用户的口令
Conn.Password = "ohmydear";
//设定用于执行WMI操作的范围
System.Management.ManagementScope Ms = new ManagementScope("\\\\" + "10.0.0.254" + "\\root\\cimv2", Conn);
try
{
//连接到实际操作的WMI范围
Ms.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Ms, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
if (m["Name"].ToString() == "oracle.exe")
{
result = true;
break;
}
else if (m["Name"].ToString() == "java.exe")
{
result = true;
}
else
{
result = false;
}
}
}
catch (Exception e)
{
throw e;
}
return result;
}
//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 * 1024);
// }
//}
//return totalSize;
远程监控磁盘使用情况:
long mb = 1048576;
//1024x1024
//设定生成的WMI所需的所有设置
System.Management.ConnectionOptions Conn = new ConnectionOptions();
//设定用于WMI连接操作的用户名
Conn.Username = "Administrator";
//设定用户的口令
Conn.Password = "ohmydear";
//设定用于执行WMI操作的范围
System.Management.ManagementScope Ms = new ManagementScope("\\\\" + "10.0.0.254" + "\\root\\cimv2", Conn);
try
{
//连接到实际操作的WMI范围
Ms.Connect();
//设定通过WMI要查询的内容
ObjectQuery Query = new ObjectQuery("select FreeSpace ,Size ,Name from Win32_LogicalDisk where DriveType=3");
//WQL语句,设定的WMI查询内容和WMI的操作范围,检索WMI对象集合
ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Ms, Query);
//异步调用WMI查询
ManagementObjectCollection ReturnCollection = Searcher.Get();
double free = 0;
double use = 0;
double total = 0;
//listBox1.Items.Clear ( ) ;
//通过对产生的WMI的实例集合进行检索,获得硬盘信息
foreach (ManagementObject Return in ReturnCollection)
{
if (Return["Name"].ToString() == "D:")
{
//获得硬盘的可用空间
free = Convert.ToInt64(Return["FreeSpace"]) / mb;
//获得硬盘的已用空间
use = (Convert.ToInt64(Return["Size"]) - Convert.ToInt64(Return["FreeSpace"])) / mb;
//获得硬盘的合计空间
total = Convert.ToInt64(Return["Size"]) / mb;
}
}
}
catch (Exception ee)
{
//MessageBox.Show ( "连接" + textBox1.Text + "出错,出错信息为:" + ee.Message ,"出现错误!" ) ;
}
//查看本地进程运行状况
foreach (Process[] thisproc in System.Diagnostics.Process.GetProcesses("10.0.0.147"))
{
if (thisproc.ProcessName == "Foxmail")
{
result = true;
break;
}
else if (thisproc.ProcessName == "QQ")
{
result = true;
}
else
{
result = false;
}
}
//远程查看计算机的服务运行状况
public bool FindProcess(string ProcessName)
{
bool result = false;
System.Management.ConnectionOptions Conn = new ConnectionOptions();
//设定用于WMI连接操作的用户名
Conn.Username = "Administrator";
//设定用户的口令
Conn.Password = "ohmydear";
//设定用于执行WMI操作的范围
System.Management.ManagementScope Ms = new ManagementScope("\\\\" + "10.0.0.254" + "\\root\\cimv2", Conn);
try
{
//连接到实际操作的WMI范围
Ms.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(Ms, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
if (m["Name"].ToString() == "oracle.exe")
{
result = true;
break;
}
else if (m["Name"].ToString() == "java.exe")
{
result = true;
}
else
{
result = false;
}
}
}
catch (Exception e)
{
throw e;
}
return result;
}
相关文章推荐
- 【转】iotop命令,监控进程使用磁盘io情况
- 监视磁盘使用情况的Shell脚本(本地+远程)
- Spark的Straggler深入学习(1):如何在本地图形监控远程Spark的GC情况——使用java自带的jvisualvm
- CentOS6.5下使用NetHogs监控进程网络使用情况
- nagios监控swap usage,HTTP,负载情况,磁盘使用,内存
- Mac使用sshfs挂载远程磁盘到本地
- zabbix监控windows服务器上进程的内存使用情况
- 使用本地JConsole监控远程JVM (转)
- C#获取本地或远程磁盘使用信息
- 使用本地JConsole监控远程JVM(最权威的总结)
- 使用本地JConsole监控远程JVM(最权威的总结)
- » 在 Ubuntu 上使用 sshfs 映射远程 ssh 文件系统为本地磁盘 Wow! Ubuntu
- 64位操作系统在本地安装oracle数据库的情况下,怎么使用plsql连接远程或者本地的oracle数据
- 监控磁盘使用情况
- NET(C#)使用WMI事件查询实现对进程和可移动磁盘的监控
- 在本地没有安装Oracle的情况下,使用plsql远程连接数据库
- 使用JConsole监控进程、线程、内存、cpu、类情况
- C#小伎俩获取本地或远程磁盘使用信息
- 使用Java自带的VisualVM监控远程主机JVM内存使用情况