2

So I am trying to get my application to delete itself on exit.

I am currently using this (found here):

Process.Start("cmd.exe", 
"/C choice /C Y /N /D Y /T 3 & Del " + Application.ExecutablePath);
Application.Exit();   

The CMD window comes up, but will not remove the application. Any ideas why not?

EDIT: So it works sometimes... other times it does not... ideas?

Jeff B
  • 8,572
  • 17
  • 61
  • 140
dwb
  • 475
  • 6
  • 31

1 Answers1

2

I think the problem is that you cannot delete an application while it's running. You could introduce some delay in the cmd command(I don't know how), or you could simply make another application with a timer set on 5 sec. And insert the code:

System.IO.File.Delete(Application.ExecutablePath)
Me.Close

Then just use the Process.Start("your/Delete/App/Path.exe") in the first app.

Zetko
  • 46
  • 3