首页 > 其他 > 详细

C#利用ntsd.exe关闭进程

时间:2014-03-26 11:38:26      阅读:595      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣

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         }
bubuko.com,布布扣

C#利用ntsd.exe关闭进程,布布扣,bubuko.com

C#利用ntsd.exe关闭进程

原文:http://www.cnblogs.com/shanlin/p/3620791.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!