• 远程服务器监控程序浅谈


    参考文献:

    用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对象名单

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

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

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

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

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

    
  • 相关阅读:
    sqlite遇到database is locked问题的完美解决
    Delphi使程序的窗口出现在最前面并激活
    win10 家庭版不支持gpedit.msc的解决办法
    Delphi Record To Stream
    SQL Server 查看CPU情况
    JavaScript 获取 Url 上的参数(QueryString)值
    关于EF分页查询报错(Count must have a non-negative value.)的解决方案
    调用微信退款接口时出现System.Security.Cryptography.CryptographicException: 出现了内部错误 解决办法
    Javascript中“==”与“===”的区别
    IE浏览器各版本的CSS Hack
  • 原文地址:https://www.cnblogs.com/itshare/p/2001392.html
Copyright © 2020-2023  润新知