您将需要使用
System.Diagnostics.Process.Kill方法。您可以获得所需的过程
System.Diagnostics.Proccess.GetProcessesByName。
原文链接:https://www.f2er.com/vb/256553.htmlSystem.Diagnostics.Proccess.GetProcessesByName。
示例已经在这里发布,但我发现非.exe版本工作更好,所以像:
foreach ( Process p in System.Diagnostics.Process.GetProcessesByName("winword") ) { try { p.Kill(); p.WaitForExit(); // possibly with a timeout } catch ( Win32Exception winException ) { // process was terminating or can't be terminated - deal with it } catch ( InvalidOperationException invalidException ) { // process has already exited - might be able to let this one go } }
你可能不需要处理NotSupportedException,这表明该进程是远程的。