Hi,
im making a small program that deletes a file open in another program?
for example:
if myfile.txt is open in a text editor in read write mode,
then normally windows wont allow me to delete it or move it, right?
so how will I find the name of the text file editors process?
then if I kill it with TerminateProcess() I can safely delete myfile.txt...:)
Is there an easy way of doing this?
Please help:)
You need to perform a global string-handle check, OR check inside all processes if they posses the handle for the specific file Close the handle.
If not do nothing.
It is NOT recommended to close the handle because the 3rd party process will have no way of knowing it and the following problem may occur:
- The handle will be reused by the kernel sooner or later.
- 3rd party process thinks the file is still opened and it will then close something you didn't intend to close. This problem can be very hard to track down because it never reproduces the same way twice.
@modoran:
how will I know in which program is myfile.txt is opened ?
If i get the path to the exe then i can know the process name and I can kill it with TerminateProcess(), by getting PID of exe!
Please help?