private void 结束进程ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("警告:终止进程会导致不希望发生的结果,\r包括数据丢失和系统不稳定。在被终止前,\r进程将没有机会保存其状态和数据。确实\r想终止该进程吗?", "任务管理器警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                {
                    string ProcessName = listView1.SelectedItems[0].Text;
                    Process[] MyProcess = Process.GetProcessesByName(ProcessName);
                    MyProcess[0].Kill();
                    getProcessInfo();
                }
                else
                { }
            }
            catch
            {
                string ProcessName = listView1.SelectedItems[0].Text;
                Process[] MyProcess1 = Process.GetProcessesByName(ProcessName);
                Process MyProcess = new Process();
                //设定程序名
                MyProcess.StartInfo.FileName = "cmd.exe";
                //关闭Shell的使用
                MyProcess.StartInfo.UseShellExecute = false;
                //重定向标准输入
                MyProcess.StartInfo.RedirectStandardInput = true;
                //重定向标准输出
                MyProcess.StartInfo.RedirectStandardOutput = true;
                //重定向错误输出
                MyProcess.StartInfo.RedirectStandardError = true;
                //设置不显示窗口
                MyProcess.StartInfo.CreateNoWindow = true;
                //执行强制结束命令
                MyProcess.Start();
                MyProcess.StandardInput.WriteLine("ntsd -c q -p " + (MyProcess1[0].Id).ToString());
                MyProcess.StandardInput.WriteLine("Exit");
                getProcessInfo();
            }
        }关闭进程用MyProcess[0].Kill();
这个不是就好了吗
红色字体是干什么的...求解释....谢谢...

解决方案 »

  1.   


     string ProcessName = listView1.SelectedItems[0].Text;
                    Process[] MyProcess1 = Process.GetProcessesByName(ProcessName);
                    Process MyProcess = new Process();
                    //设定程序名
                    MyProcess.StartInfo.FileName = "cmd.exe";
                    //关闭Shell的使用
                    MyProcess.StartInfo.UseShellExecute = false;
                    //重定向标准输入
                    MyProcess.StartInfo.RedirectStandardInput = true;
                    //重定向标准输出
                    MyProcess.StartInfo.RedirectStandardOutput = true;
                    //重定向错误输出
                    MyProcess.StartInfo.RedirectStandardError = true;
                    //设置不显示窗口
                    MyProcess.StartInfo.CreateNoWindow = true;
                    //执行强制结束命令
                    MyProcess.Start();
                    MyProcess.StandardInput.WriteLine("ntsd -c q -p " + (MyProcess1[0].Id).ToString());
                    MyProcess.StandardInput.WriteLine("Exit");

    求解释这几句
      

  2.   

    出异常的时候 直接使用ntsd明令 来干掉进程