使用Process类查看进程并操作进程
主要代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 对进程操作
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGetAllPro_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
Process[] pros = Process.GetProcesses();
for (int i = 0; i < pros.Length; i++)
{
listBox1.Items.Add(pros[i].ProcessName);
}
}
private void btnKillPro_Click(object sender, EventArgs e)
{
if (listBox1.Items.Count > 0)
{
string name =(string) listBox1.SelectedItem;
Process[] pross = Process.GetProcessesByName(name);
for (int i = 0; i < pross.Length; i++)
{
pross[i].Kill();
}
}
}
}
}