c#关闭系统进程以及如何调用cmd并执行命令

2025-04-14 12:28:44
推荐回答(1个)
回答1:

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());//直接结束进程ID MyProcess.StandardInput.WriteLine("Exit"); 第二种,通过强大的进程类进行标准关闭。