Reputation: 42443
How can I find which processes have a specific file opened, and their open, access and share modes? Additionally, is it possible to change these values for a process? Or is it even possible to open a file for reading if it is already opened for exclusive access by another process?
Please note that I don't want to invalidate the handle of the process having the file opened. I just want to be able to access the file (if possible).
(I'm mainly asking about Windows, but solutions for other platforms are welcome, since they contribute to the community's knowledge.)
Edit: I found some answers for my first question here and there.
Edit 2: Thanks everybody for the tools you mentioned, but I am mainly looking for programmatical techniques (e.g. using Win32 APIs).
Upvotes: 2
Views: 3525
Reputation: 10747
Im not sure if there is a way to do exactly what you want but I do know that using System.Diagnostics.Process class (at least in .Net) you can open processes and watch for certain properties:
System.Diagnostics.Process[] procArray = System.Diagnostics.Process.GetProcessesByName("notepad");
foreach (System.Diagnostics.Process proc in procArray) {
//do something with the process...
}
Look around the Process class, maybe there is a property or collection to get the data you are looking for.
Upvotes: -1
Reputation: 127428
For unix you can use fuser
:
lnx0:i386_linux26> fuser -v a.cpp
USER PID ACCESS COMMAND
a.cpp nabcdefg 3952 f.... less
Upvotes: 1
Reputation:
For windows, I know about a Tool from Sysinternal (www.sysinternals.com): handle.exe.
Upvotes: 3