1.将ntsd.exe复制到C:\Windows\System32\目录下 1 /// <summary> 2 /// 关闭进程<br/> 3 /// </summary> 4 /// <param name="name">进程名</param> 5 /// <param name="id">进程ID</param> 7 /// <returns></returns> 8 public static bool KillProcess(string name, int id) 9 { 11 bool result = false;//判断进程是否运行的标识 12 Process[] prc = Process.GetProcesses(); 13 if (name == null) name = ""; 14 name = name.Replace(".EXE", "").Replace(".exe", ""); 15 try 16 { 19 Process process = new Process(); 20 try 21 { 22 process.StartInfo.FileName = "cmd.exe"; 23 process.StartInfo.UseShellExecute = false; 24 process.StartInfo.RedirectStandardInput = true; 25 process.StartInfo.RedirectStandardOutput = true; 26 process.StartInfo.RedirectStandardError = true; 27 process.StartInfo.CreateNoWindow = true; 28 process.Start(); 29 30 if (id == 0 && !String.IsNullOrEmpty(name)) 31 { 32 Process[] proArr = Process.GetProcessesByName(name); 33 if (proArr.Length > 0) 34 { 35 id = proArr[0].Id; 36 } 37 } 38 if (id != 0) 39 { 40 process.StandardInput.WriteLine("ntsd -c q -p " + id);//直接结束进程ID 41 process.StandardInput.WriteLine("Exit"); 42 } 43 //else 44 //{ 45 // process.StandardInput.WriteLine("ntsd -c q -pn " + name+".exe"); 46 // process.StandardInput.WriteLine("Exit"); 47 //} 48 } 49 catch (Exception) 50 { 51 foreach (Process pr in prc) //遍历整个进程 52 { 53 if (pr.ProcessName == name) 54 { 55 pr.Kill(); 56 result = true; 57 } 58 } 59 } 60 finally 61 { 62 if (process != null) 63 process.Dispose(); 64 } 65 } 66 catch (Exception ex) 67 { 68 TxtLog.InsertLog(ex, "Helper KillProcess"); 69 } 70 71 return result; 72 }
C#利用ntsd.exe关闭进程,布布扣,bubuko.com
原文:http://www.cnblogs.com/shanlin/p/3620791.html