Is there any way to determine if a file is open by anything include applications that do not lock the file (like notepad).
I need to detect when a given file myfile.txt is no longer open in any application including notepad - so i cannot use File.Open(...) with exclusive access to test since the file has no lock on it.
3. View recently opened files from other users on the same computer by clicking inside the File Explorer location bar and replacing the current user's name with a different user. Alternately, type “C:\Users\Username\Recent” into the location bar in (omitting quotes) and press “Enter.”
System Tools > Shared Folders > Open Files This pane will display a list of all open files being accessed on that server in a Windows Server environment. Inside, you'll see the directory path of the file being accessed, the user's username, the file's status, and the number of locks on the file.
The command lsof -t filename shows the IDs of all processes that have the particular file opened. lsof -t filename | wc -w gives you the number of processes currently accessing the file.
No. When Notepad has opened a file, it has read the entire file in and then closed it. So there is no trace in the OS that links Notepad's private memory with the file on disk.
Opening the file exclusively will not work, because Notepad does not have the file open. Searching Notepad's handle table will not work, because Notepad does not have the file open.
The only way to detect this is to write an unmanaged DLL that is injected into every process to scan their virtual memory, searching for the exact file contents. Not recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With