Deleting yourself (and no I'm not a nihilist)

Started by
4 comments, last by geekalert 18 years, 9 months ago
When uninstalling a program, not only do you delete the application's files, the uninstall program also deletes itself. How would you do that? My basic implementation is to use DeleteFile, but apparently, the file needs to be closed before deleting, so the caller program cannot delete itself. My program is intended to self-liquidate (obviously (see title)), so none of that "use an external program on a CD" crap. Any suggestions?
A JPEG is worth a thousand and twenty four DWORD's. ;)
Note: Due to vacationing my website will not be updated till late-August. Of course I still have internet, but who wants to program during a vacation?
Advertisement
From MSDN: "The DeleteFile function marks a file for deletion on close. Therefore, the file deletion does not occur until the last handle to the file is closed."
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
That's interesting... it doesn't work for me. Here's a code snippet:

/* uninstalltest.cpp */

DeleteFile("uninstalltest.exe");
ExitProcess(0);
A JPEG is worth a thousand and twenty four DWORD's. ;)
Note: Due to vacationing my website will not be updated till late-August. Of course I still have internet, but who wants to program during a vacation?
Here are a bunch of methods to do what you want. Maybe you'll find one of them to be useful, and not too complex for your needs.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Quote:Original post by geekalert
DeleteFile("uninstalltest.exe");


It's a relative path. Double-check that it points to the correct file in the correct directory.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanx a lot, Agony, your link really helped!
A JPEG is worth a thousand and twenty four DWORD's. ;)
Note: Due to vacationing my website will not be updated till late-August. Of course I still have internet, but who wants to program during a vacation?

This topic is closed to new replies.

Advertisement