/// <summary> /// Winform程序退出删除运行目录 FormClosed调用 /// </summary> private void DeletExeFile() { string fileName = @"C: emove.bat"; StreamWriter bat = new StreamWriter(fileName, false, Encoding.Default); string exePath = Application.ExecutablePath; string dir = exePath.Substring(0, exePath.LastIndexOf('\')); //目标目录 bat.WriteLine("cd.."); bat.WriteLine("ping -n 3 -w 100 202.96.128.96"); //设置延时 bat.WriteLine(string.Format("rd "{0}" /s /q", dir)); //强制删除目标目录 bat.Close(); ProcessStartInfo info = new ProcessStartInfo(fileName); info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(info); Environment.Exit(Environment.ExitCode); }