Remove the file after starting it

Sep 12, 2014 at 11:44pm
Hey, I'm looking for a way to remove the file after you've started it, I've tried via TerminateProcess and then forced ALL_ACCESS (since the file is in use when you run it) and then try remove the file but that doesn't work for the file you're "currently" using.

So how do you remove the file you're currently using (.exe)?
If you can give a example/snippet code, do so.

Thanks in advance.
Last edited on Sep 12, 2014 at 11:55pm
Sep 13, 2014 at 12:26am
Don't know what you are talking about. Sorry can't help you.
Sep 13, 2014 at 5:18am
Also not sure, but might try to help anyway:
If you're talking about deleting a file that the program is using (like a data file being read into the program), there is no way in just C++ to delete files, only to create them.
To delete files you would need to use OS-specific code.

For a program to be able to delete its own executable file, you would also having to use platform-specific code libraries, so I would suggest using google, this seems promising http://stackoverflow.com/questions/3457040/how-to-write-a-program-in-c-such-that-it-will-delete-itself-after-execution
Sep 13, 2014 at 7:25am
Sep 13, 2014 at 8:38pm
novellof: Simply: start .exe and then remove .exe.
Thanks all! Especially the latest link, solved it.
Topic archived. No new replies allowed.