I know how to display attached modules but how do i check if a file is locked by a dll.
thanks
Printable View
I know how to display attached modules but how do i check if a file is locked by a dll.
thanks
A DLL cant lock a file on its own - a process calling functions from a DLL could lock a file, but you cant just say a DLL has locked a file because one process could be using that DLL and locking a file but another process could be using that DLL and not locking any files. I'm guessing the only reason you would want to know what is locking a file is so that you can do something about it... and you cant do anything about it just by knowing which DLL holds the function that is locking the file - you need to know which process it is that is locking the file.
So personally I would have thought the only way you could find out which process is locking a file is to loop through all active processes and enumerate the handles that each process has. I dont think there is any way in .NET to get a list of the open handles that a process has though so you would probably have to look at some Windows APIs and even then I'm guessing it will not be a trivial task to actually find out which handles relate to which object (I say object because a process can have handles to more than just files, it can be registry keys, kernel objects etc). I might be wrong, there might be an easy (ish) way to do it but I think this might require quite a lot of work. Its definitely possible as programs like Process Monitor can list all open handles for each process, but then they are written in C++...