根据进程名获取PID
/* * Created by SharpDevelop. * User: Wzqa * Date: 2012/12/2 * Time: 14:08 * * 根据进程名获取PID. */ using System; using System.Diagnostics; namespace PID { class Program { public static void Main(string[] args) { Console.Write(GetPidByProcessName("1")); //不用加后缀名 ".exe" Console.ReadKey(true); } public static int GetPidByProcessName(string processName) { Process[] arrayProcess = Process.GetProcessesByName(processName); foreach (Process p in arrayProcess) { return p.Id; } return 0; } } }