I was wondering whether there is a way for a program to delete itself after it is terminated. At the moment I am doing it through the 'RunOnce' registry entry, but this only delete the application when the computer is restarted.
Hey hey
If we are discuusing the ideas then here's one. Sorry I don't have time to write sample code at the moment, but the idea is quite simple. I was doing it when needed to make self updating application.
Idea:
Every time the application (APP1) is started, it starts another instance of itself with some param, say ProcessID (APP2). Once APP2 is started it does nothing but waits for APP1 to terminate (WaitForSingleObject). Once APP1 is closed/terminated, APP2 does all dirty things it needs to do and terminates.
Hey ther
I guess I didn't explain my idea full enough
well going further: Windows surely will not allow to delete a program that is currently running, but prior to starting a second instance of you APP you can copy it to another file, say, you program's name is MyApp.exe, when it starts it copies itself to MyApp2.exe and then starts MyApp2.exe with a param that you'd specify. Hence, when MyApp.exe terminates MyApp2.exe would catch that event as explained above, and MyApp2.exe would delete MyApp.exe. Though while typing this I ralized that that approach was good for selfupdating files and in your case that would still leave a copy of an application on a computer...
Sorry may be the idea wasn't that good.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.