C# 强制关闭当前程序进程(完全Kill掉不留痕迹)
C#代码
class="Apple-converted-space">
-
-
-
-
-
- public static string RunCmd(string command)
- {
-
- System.Diagnostics.Process p = new System.Diagnostics.Process();
-
-
-
- p.StartInfo.FileName = "cmd.exe";
- p.StartInfo.Arguments = "/c " + command;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true;
-
- p.Start();
-
-
-
-
- return p.StandardOutput.ReadToEnd();
-
- }
在Program.cs加上如下
C#代码
- static class Program
- {
-
-
-
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MainForm());
-
- string exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
- string[] exeArray = exeName.Split('\\');
-
- FunctionClass.RunCmd("taskkill /im " + exeArray[exeArray.Length-1] + " /f ");
- }
- }