hello, I writed a program, that when it is running, it will copy itself, and make the copied one to run. The copied one's dwFlagsAndAttributes is FILE_FLAG_DELETE_ON_CLOS, I mean to make the copied one disappeared when it no longer used.

then the questions are :
1. bucause the copied one's dwFlagsAndAttributes is FILE_FLAG_DELETE_ON_CLOS, so when I create the file and colose it's handle, it will Disappear, so I cannot run it.
2. If I first give the dwFlagsAndAttributes FILE_ATTRIBUTE_ARCHIVE, then colose it's handle, but when the copied one no longer used, it will not Disappear.
how can I create that file and make it running?
Posted on 2004-11-21 09:09:08 by miaomiao
Try these steps:

- Create file with FILE_FLAG_DELETE_ON_CLOSE
- Write file contents
- Run the file
- Close handle to file. CreateProcess (or ShellExecute, whatever you're using) will open a handle to the file and prevent the file from being deleted until the process exits.

I'm not sure if CreateProcess will work on files that have handles with write-access open, so you may need to first write the file, close the file, and then re-open it readonly with FILE_FLAG_DELETE_ON_CLOSE.
Posted on 2004-11-22 03:28:38 by Qweerdy
Try these steps:

- Create file with FILE_FLAG_DELETE_ON_CLOSE
- Write file contents
- Run the file
- Close handle to file. CreateProcess (or ShellExecute, whatever you're using) will open a handle to the file and prevent the file from being deleted until the process exits.

I'm not sure if CreateProcess will work on files that have handles with write-access open, so you may need to first write the file, close the file, and then re-open it readonly with FILE_FLAG_DELETE_ON_CLOSE.


Thank for your reply, but when "- Close handle to file.", the file will disappear, so "CreateProcess" will NOT work.
Posted on 2004-11-22 07:01:47 by miaomiao