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.
That's all.
--- McMerfy