Below, you can find a link to the source code with the function(s) to make a binary delete itself. Under Microsoft Windows it’s not possible to make an executable delete itself. That’s the reason why the function first creates a batch script that deletes the binary file and afterwards itself.
Source : How to make a program to delete itself
Mar 7th, 2009 by carrumba
2 responses to “Source : How to make a program to delete itself”
Leave a comment
But please respect the commenting rules. Critizism is appreciated and also general comments of course. If you're rude your comment will be deleted. Also use your personal/nick name but avoid using business names. Thanks!

Actually, you can (if you’re admin or the drive has weak permissions) use the defrag API to get the clusters backing any file at all, and read from them (read the SAM file?) or write to them (clobber the event log?). I don’t remember whether windows will write the executable back to disk later, that would be something to toy with though. So your executable should be able to grab its disk clusters and wipe them…
If your application creates files on the harddisk I’d recommend to encrypt it anyway so in case someone is able to recover them they’re useless to him. But to delete files the way you mentioned would be preferable. It’s cleaner.
Expect you will encounter the same problem you can’t delete yourself.
I remember there’s an other source folating around on my disk … I’ll post it as soon i’ve found it.