Introduce namespace: using System.Diagnostics;
Start a process, for example, open Notepad:
Process process1 = new Process();
process1.StartInfo.FileName = "NotePad.exe";
process1.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process1.Start();
Terminate a process:
Process[] p = Process.GetProcessesByName("NotePad");
if (p.Length >0)
{
if (!p[0].HasExited)
{
if (p[0].Responding)
{
p [0].CloseMainWindow();
}
else
{
p[0].Kill();
}
}
}
The thread's HasExited property is used to determine whether the thread has been closed. If the process has been shut down, a true attribute value will be returned; if the process is still running, a false attribute value will be returned.
The thread's Responding property determines whether the process's user interface is responding. When an attempt is made to read the Response property, a request is sent to the user interface of the target process. If there is an immediate response, the returned attribute value is trues, and the CloseMainWindow method can be called to close the application; if the interface does not respond, the false attribute value is returned, and the Kill method can be called to force the process to close.
http://www.cnblogs.com/KissKnife/archive/2006/08/13/475704.html