search
HomeBackend DevelopmentC#.Net TutorialHow to obtain the machine's memory and CPU information?
How to obtain the machine's memory and CPU information?Jun 23, 2017 pm 04:09 PM
memoryhowmachineObtain

I recently worked on a project where I needed to obtain the CPU and memory usage of the machine. I spent some time searching online and did some testing myself. To sum up, there are basically two ways: one is to use WMI (2 types), and the other is to use Performance counter.

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";

                       through '''''' ( ); ##                                                                                                                                                                                        mos. , cannot be used, finally found this class "Win32_PerfRawData_PerfOS_Memory"

ManagementObjectCollection mcr = mcp.getQueryResult("select * from Win32_ComputerSystem");

         

                                     {

                                                                                                                                                                               }

        }

ManagementObjectCollection MOC = mcp.getQueryResult ("Select * from Win32_perFrawdata_perfos_memory");

Foreach (Managementobject MoC) {

String avilable = MO.GetPropertyValue ("AvailableBytes"). Tostring ();

avilablem = long.parse (avilation);

}

2. Get Local'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.



Although these are relatively simple, I still want to record them. I hope they can be useful to everyone!

The above is the detailed content of How to obtain the machine's memory and CPU information?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
使用math.Max函数获取一组数中的最大值使用math.Max函数获取一组数中的最大值Jul 24, 2023 pm 01:24 PM

使用math.Max函数获取一组数中的最大值在数学和编程中,经常需要找出一组数中的最大值。在Go语言中,我们可以使用math包中的Max函数来实现这个功能。本文将介绍如何使用math.Max函数来获取一组数中的最大值,并提供相应的代码示例。首先,我们需要导入math包。在Go语言中,导入包可以使用import关键字,如下所示:import"mat

CAMM2 for desktop PCs: MSI explains the benefits of the new RAM standard for gaming towersCAMM2 for desktop PCs: MSI explains the benefits of the new RAM standard for gaming towersAug 17, 2024 pm 06:47 PM

The first LPCAMM2 modules for laptops are already being delivered, and desktop mainboards are also expected to be equipped with CAMM2 in future. CAMM2 and LPCAMM2 are not compatible with each other, and even on desktop PCs, customers need to be caref

「从未被制造出的最重要机器」,艾伦·图灵及图灵机那些事「从未被制造出的最重要机器」,艾伦·图灵及图灵机那些事Jun 25, 2023 pm 07:42 PM

计算是我们大多数人凭直觉就能理解的一个熟悉概念。我们以函数f(x)=x+3为例,当x为3时,f(3)=3+3。答案是6,非常简单。很明显,这个函数是可计算的。但是有些函数并非那么简单,而且要确定它们是否可以计算也非易事,这意味着它们可能永远都无法得出一个最终答案。1928年,德国数学家大卫・希尔伯特(DavidHilbert)和威廉・阿克曼(WilhelmAckermann)提出了一个名为Entscheidungsproblem(即「判定性问题」)的问题。随着时间推移,他们提出的这个问题将引出可

如何在Java中获取LinkedHashSet的最后一个元素?如何在Java中获取LinkedHashSet的最后一个元素?Aug 27, 2023 pm 08:45 PM

从Java中的LinkedHashSet中检索最后一个元素意味着检索其集合中的最后一个元素。尽管Java没有内置方法来帮助检索LinkedHashSets中的最后一个项,但存在多种有效的技术,可以提供灵活性和便利性,有效地检索此最后一个元素而不破坏插入顺序-这是Java开发人员必须在其应用程序中有效处理的问题。通过将这些策略有效地应用于他们的软件项目中,他们可以实现满足此要求的最佳解决方案LinkedHashSetLinkedHashSet是Java中的一种高效数据结构,它结合了HashSet和

Java程序获取给定文件的大小(以字节、千字节和兆字节为单位)Java程序获取给定文件的大小(以字节、千字节和兆字节为单位)Sep 06, 2023 am 10:13 AM

文件的大小是特定文件在特定存储设备(例如硬盘驱动器)上占用的存储空间量。文件的大小以字节为单位来衡量。在本节中,我们将讨论如何实现一个java程序来获取给定文件的大小(以字节、千字节和兆字节为单位)。字节是数字信息的最小单位。一个字节等于八位。1千字节(KB)=1,024字节1兆字节(MB)=1,024KB千兆字节(GB)=1,024MB和1太字节(TB)=1,024GB。文件的大小通常取决于文件的类型及其包含的数据量。以文本文档为例,文件的大小可能只有几千字节,而高分辨率图像或视频文件的大小可

win10内存管理引发的蓝屏问题win10内存管理引发的蓝屏问题Dec 30, 2023 pm 07:11 PM

win10系统是一款非常值得使用的优秀系统,强大的兼容性和高智能可以确保win10系统在使用中基本不会出现什么问题,但近日却有很多小伙伴们反应自己的电脑出现了频繁蓝盘并且老是提示错误代码memorymanagement这是怎么回事呢?今天小编就为大家带来了win10频繁蓝屏并且出现了memorymanagement终止代码的解决办法游戏需要的话就快来看看吧。win10memorymanagement蓝屏的解决办法:解决方法一:1、使用“Win键+R”+输入“control+enter”进入控制面

使用path/filepath.Ext函数获取文件路径的扩展名部分使用path/filepath.Ext函数获取文件路径的扩展名部分Jul 25, 2023 pm 08:42 PM

使用path/filepath.Ext函数获取文件路径的扩展名部分在编程过程中,经常会遇到需要获取文件的扩展名的需求。Go语言提供了一个非常方便的函数path/filepath.Ext来实现这个功能。本文将介绍如何使用该函数来获取文件路径的扩展名部分。首先,让我们来看一个简单的示例:packagemainimport("fmt&q

MySQL储存引擎选型对比:InnoDB、MyISAM与Memory性能指标评估MySQL储存引擎选型对比:InnoDB、MyISAM与Memory性能指标评估Jul 26, 2023 am 11:25 AM

MySQL储存引擎选型对比:InnoDB、MyISAM与Memory性能指标评估引言:在MySQL数据库中,储存引擎的选择对于系统性能和数据完整性起着至关重要的作用。MySQL提供了多种储存引擎,其中最常用的引擎包括InnoDB、MyISAM和Memory。本文将就这三种储存引擎进行性能指标评估,并通过代码示例进行比较。一、InnoDB引擎InnoDB是My

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),