怎么获取CPU和内存相关信息(最好有源码)

如何获取CPU和内存相关信息(最好有源码)
如何获得内存的CPU的使用量以及每个进程的CPU的使用量
如何获得当前计算机的物理内存大小以及使用的物理内存的使用量
最好有源码

------解决方案--------------------
Process名字替换掉_Total可以得到相应进程的cpu使用

C# code
public partial class Form1 : Form
    {
        PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", [color=#FF0000]"_Total"[/color]); 

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double cpu = getCurrentCpuUsage();
            double Freemem = getAvailableRAM();
            double usedMem = getCommitedRAM();
        }

        public double getCurrentCpuUsage()
        { 
            return cpuCounter.NextValue();
        } 

        /* 
        Call this method every time you need to get 
        the amount of the available RAM in Mb 
        */ 
        public double getAvailableRAM()
        {       
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
            return ramCounter.NextValue(); 
        } 


        /* 
        Call this method every time you need to get 
        the amount of the available RAM in Mb 
        */ 
        public double  getCommitedRAM()
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Committed Bytes");
            return ramCounter.NextValue();
        } 

    }

------解决方案--------------------
您只需要在VB.NET中加入PerformanceCounter组件,并把该组件的categoryname 设置为processor,其他属性就按照你需要的选择即可.当然,不要忘记把machinename设置为想要监视的机器名(不设置就是本机).