使用System.Diagnostics.Process类可以启动和停止系统进程。GetProcesses函数返回了机器上正在运行的所有进程,它有两种定义,一种是用于本地机器,另一种用于远程机器。
如果想要获取本地机器上的运行进程,使用GetProcesses();否则使用GetProcesses(stringmachinename):
public static Process[] GetProcesses();
public static Process[] GetProcesses(string);
比如:
Process[] procList = new Process[100];
procList = Process.GetProcesses();
for ( int i=0; i<20; i++)
{
string strProcName = procList[i].ProcessName;
int iProcID = procList[i].Id;;
}
请不要忘记引用System.Diagnostic,将以下这行代码写在using列表中:
using System.Diagnostics;
通过使用Process类的方法,我们甚至可以启动、停止或取消进程。