How to tell if a file is open by someone else
-
I have a program that manages documents on a central area in the network and I need to tell if a file is in use by someone ele, when I try to open it. The program runs on each machine that access the central archive (no program runs on the server that holds the files). What is the right or the best way to do it ? Can I try to lock the file or rename it and see by the error returned if the file is open ? Is there any API function that tells me that ? If it´s a Word Doc, for instance, the Word gives me a hint, but Notepad doesn´t. I want to send my own msg to the user, despite of the app used to open the file. Is it possible ?
-
I have a program that manages documents on a central area in the network and I need to tell if a file is in use by someone ele, when I try to open it. The program runs on each machine that access the central archive (no program runs on the server that holds the files). What is the right or the best way to do it ? Can I try to lock the file or rename it and see by the error returned if the file is open ? Is there any API function that tells me that ? If it´s a Word Doc, for instance, the Word gives me a hint, but Notepad doesn´t. I want to send my own msg to the user, despite of the app used to open the file. Is it possible ?
-
check out sdk's CreateFile() proc. if specified file is somehow locked, you get an invalid handle. you may then call GetLastError(): hope this helps...
or you could look at good old _sopen, passing the _SH_DENYRW flag onwards and upwards...