资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

获取机器memory和CPU信息的方法是什么

小编给大家分享一下获取机器memory和CPU信息的方法是什么,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

创新互联长期为1000多家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为兴文企业提供专业的成都网站制作、网站建设,兴文网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

1. Use WMI to create connection to the computer passing username and password. Once the connection is created,  query the CPU& memory by passing the query, similar as SQL.  This way can get CPU & memory for remote PC and local PC. For example:

System.Management.ConnectionOptions Conn = new ConnectionOptions();

Conn.Username = mpusername;

Conn.Password = mppwd;

string scopestring = "//" + mpserver + "/root/cimv2";

System.Management.ManagementScope Ms = new ManagementScope(scopestring);

Ms.Connect();

mos.Scope = Ms;

ObjectQuery oq = new ObjectQuery();

oq.QueryString = "select * from Win32_Processor";

mos.Query = oq;

ManagementObjectCollection moc = mos.Get();

内存这块花了比较多的时间,之前的对象已经过期,不能使用了,最后找到这个类“Win32_PerfRawData_PerfOS_Memory”

ManagementObjectCollection mcr = mcp.getQueryResult("select * from Win32_ComputerSystem");
           
           foreach (ManagementObject mo in mcr)
           {
               if (mo["TotalPhysicalMemory"] != null)
               {
                   totalm = long.Parse(mo["TotalPhysicalMemory"].ToString());
               }
           }
           ManagementObjectCollection moc = mcp.getQueryResult("select * from Win32_PerfRawData_PerfOS_Memory");
           foreach (ManagementObject mo in moc)
           {
               string avilable = mo.GetPropertyValue("AvailableBytes").ToString();
               avilablem = long.Parse(avilable);
           }

2. Get local server’s CPU and momory information passing the WMI classes, such as “Win32_Processor”, “Win32_OperatingSystem”

ManagementClass mc = new ManagementClass("Win32_OperatingSystem");

ManagementObjectCollection moc = mc.GetInstances();

3. Use performance counter to get performance data passing the performance counter name, such as monitor.PerformanceCounterFun("Processor", "_Total", "% Processor Time"). Normally we shoud get performance counter data several times, then use the average values.

看完了这篇文章,相信你对获取机器memory和CPU信息的方法是什么有了一定的了解,想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文名称:获取机器memory和CPU信息的方法是什么
文章源于:http://www.cdkjz.cn/article/pioiji.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220