远程服务器监控程序浅谈

参考文献:

用C#开发较完整的Windows任务管理器

http://www.cnblogs.com/lemony/archive/2007/04/11/708309.html 

Win32_ClassName列表名单:

http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

软件名称:远程服务器监控程序。

软件功能:监视CPU、内存、硬盘、进程的使用情况

开发方法:C# 查询WMI信息

调用接口:本地查看视图或远程访问XML文件

运行平台:WindowsXP/Windows Server2003/Windows Server2008(已测试)

一、基础知识:Win32的类库,测试程序如下:

<1>代码如下:

  
    
protected void btnOK_Click( object sender, EventArgs e)
{
try
{
#region 远程访问
// string className = txtClass.Text.Trim();
// System.Management.ConnectionOptions conn = new ConnectionOptions();
// conn.Username = "tiancomputer\\administrator";
// conn.Password = "admin";
// ManagementScope ms = new ManagementScope("\\\\tiancomputer\\root\\cimv2", conn);
// ms.Connect();
/// /ObjectQuery query = new ObjectQuery(string.Format("select * from Win32_LogicalDisk where DriveType = '{0}'", (int)(System.IO.DriveType.Fixed))); //
// ObjectQuery query = new ObjectQuery(string.Format("select * from {0}", className)); //
// ManagementObjectSearcher search = new ManagementObjectSearcher(ms, query);
// ManagementObjectCollection moc = search.Get();
// foreach (ManagementObject mo in moc)
// {
// txtMsg.Text += "\n";
// foreach (PropertyData item in mo.Properties)
// {
// txtMsg.Text += string.Format("{0} = {1}\n", item.Name, mo[item.Name]);
// }
// }
#endregion

#region 本地访问
string className = txtClass.Text.Trim();
ManagementScope ms = new ManagementScope( " \\\\tiancomputer\\root\\cimv2 " ); // ManageMentScope(path, conn):conn,不能使用本地账户
ms.Connect();
// ObjectQuery query = new ObjectQuery(string.Format("select * from Win32_LogicalDisk where DriveType = '{0}'", (int)(System.IO.DriveType.Fixed))); //
ObjectQuery query = new ObjectQuery( string .Format( " select * from {0} " , className)); //
ManagementObjectSearcher search = new ManagementObjectSearcher(ms, query);
ManagementObjectCollection moc
= search.Get();
foreach (ManagementObject mo in moc)
{
txtMsg.Text
+= " \n " ;
foreach (PropertyData item in mo.Properties)
{
txtMsg.Text
+= string .Format( " {0} = {1}\n " , item.Name, mo[item.Name]);
}
}
#endregion
}
catch (Exception ex1)
{

}
}

<2>运行效果如下:

查询计算机用户/群组信息

 远程服务器监控程序浅谈

ManageMentClass对象如下:

Win32_NetworkAdapter

Win32_NetworkAdapterConfiguration

Win32_Group

Win32_Processor

Win32_PhysicalMemory

Win32_DiskPartition

Win32_LogicalDisk

Win32_DiskDrive

Win32_CDROMDrive

Win32_BIOS

Win32_ComputerSystem

Win32_OperatingSystem

Win32_StartupCommand

……………..

详情参数见附件

 附件下载:ManageMentClass对象名单

二、  服务器监控程序运行效果

远程服务器监控程序浅谈

远程服务器监控程序浅谈

远程服务器监控程序浅谈

三、  附件代码,欢迎大家下载、修改、完善。

有改善的发我一份([email protected]),目前还没有办法做“网站信息”监控,只能通过:开始-->cmd-->isapp命令,

查到IIS程序池对应的进程占用CPU、Memory信息。

代码下载:SeverMonitor(2011.03.31 11.10).rar



你可能感兴趣的:(服务器)