Using C#, how does one figure out what process locked a file?

前端 未结 9 2072
死守一世寂寞
死守一世寂寞 2020-11-22 13:03

In Windows, how do I determine (using C#) what process locked a file?

Third-party tools are helpful, but not what I\'m looking for.

9条回答
  •  执笔经年
    2020-11-22 13:38

    I believe that you need code running in kernel mode to completely answer the question (but I haven't looked at the restart manager API).

    You can enumerate all processes and their modules - so if the file you're looking for is a module (DLL, EXE, OCX...), you're good to go. But if it's a text file for example, you have to look at the kernel handle table which you cannot see from user mode. Handle.exe has a kernel driver in order to do that.

提交回复
热议问题