通过Process类获取系统进程列表

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;  //引用

namespace ProcessApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            listBox1.Items.Add("编号" + "  " + "名称");
            //将所有的系统进程显示在列表框中
            foreach (Process a in Process.GetProcesses())
            {
                string name = a.ProcessName;
                int id = a.Id;
               // listBox1.Items.Add(a.Id+"  "+a.ProcessName);
                listBox1.Items.Add(id.ToString() + "  " + name);
            }
        }
    }
}

 

posted on 2012-07-31 10:43  流星落  阅读(415)  评论(0编辑  收藏  举报

导航