Destroy Self is a small snippet of code to allow you to delete your own exe
Only real uses I can see this for is something like an Uninstaller, But
I am sure you guys will have other ideas, anyway hope you find it useful
Comments and suggestions welcome.
private void DestroySelf()
Process p = new Process();
string Bat_File = "delus.bat";
string Bat_Path = Path.Combine(Directory.GetCurrentDirectory(), Bat_File);
string ExeName = new FileInfo(Application.ExecutablePath).Name;
StreamWriter sw = new StreamWriter(Bat_Path);
//Create batch file to delete main exe
sw.WriteLine("attrib \"" + ExeName + "\"" + " -a -s -r -h");
sw.WriteLine("del " + "\"" + ExeName + "\"");
sw.WriteLine("if exist \"" + ExeName + "\"" + " goto Repeat");
sw.WriteLine("del \"" + Bat_File + "\"");
//Start process to execute batch file.
p.StartInfo.FileName = "delus.bat";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
//Attempt to start process.
//Something went wrong :( close error found.
private void cmdClose_Click(object sender, EventArgs e)