I am trying to create a process on another machine that removes itself when this is done. I use the DELETE_ON_CLOSE flag with CreateFile. This method is a little popular, but I am having problems because I cannot execute it while it is open (it is expected, but some solutions do). To get around this, I tried to open the file with read permissions. The DELETE_ON_CLOSE flag says that it should only delete a file when all pointers to it have disappeared. I have a pointer to this with reading, I close the write descriptor, and the file deletes, leaving my open descriptor unreadable. Any other approach to this would be appreciated.
I also considered the possibility that, since this is a remote file system, something funky happens to the handles.
I cannot change the execuatble code I submit, so the self-cleaning executable is the last thing I want to do.
Running my program to clean up the service will cause it to work for an unacceptably long time due to how long it takes to destroy the service in the remote box.
source share