public static void TestForKillMyself()
{
string bat = @"@echo off
:tryagain
del %1
if exist %1 goto tryagain
del %0";
File.WriteAllText("killme.bat", bat);//写bat文件
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "killme.bat";
psi.Arguments = "\"" + Environment.GetCommandLineArgs()[0] + "\"";
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
}[/code]
///
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
string bat = @"@echo off
:tryagain
del %1
if exist %1 goto tryagain
del %0";
File.WriteAllText("killme.bat", bat);//写bat文件
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "killme.bat";
psi.Arguments = "\"" + Environment.GetCommandLineArgs()[0] + "\"";
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
}