如何获取缺少特定文件的进程名称?

时间:2011-01-02 13:28:40

标签: c# .net windows winapi

  

可能重复:
  How does one figure out what process locked a file using c#?
  How do I find out which process is locking a file using .NET?

您好,

我试图获取锁定文件(不仅是dll模块,任何文件)的进程的名称。 例如,如果进程“进程A”在“C:\ temp \ test.txt”上打开文件流,则应该检测到这一点(如果我尝试在Windows资源管理器中删除该文件,则它将被锁定,直到该进程被终止)。

Stackoverflow上有几个例子: How does one figure out what process locked a file using c#?
Determine which process (b)locks a file, programmatically (under Windows >= XP)

我尝试了上面的例子,但没有一个可行。

我还阅读了关于Win32 API函数NtQuerySystemInformation的一些想法,但我不知道如何使用它。找不到任何PInvoke代码。

2 个答案:

答案 0 :(得分:0)

我使用来自SysInternals的Process Explorer(它不需要安装,它只是一个exe)。

  1. Ctrl + F(查找句柄或dll)
  2. 键入锁定文件的名称

答案 1 :(得分:-1)

正如评论中已经提到的(由bzlm和Richard提供),handle.exe应该适合你。

相关问题