Process myProcess = new Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.Start();
// 终止进程
myProcess.Kill();
Process myProcess = new Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.Start();
// 终止进程
myProcess.CloseMainWindow();
Process myProcess = new Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.Start();
// 等待进程执行完成
myProcess.WaitForExit();
[DllImport("kernel32.dll")]
public static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
Process myProcess = new Process();
myProcess.StartInfo.FileName = "notepad.exe";
myProcess.Start();
// 获取进程句柄,并强制结束进程
TerminateProcess(myProcess.Handle, 0);
需要注意的是,强制结束一个进程可能会导致数据丢失或者系统不稳定,因此建议谨慎使用。