Identify process using a file

2019-01-23 13:46发布

I have been trying to figure out how to programmatically identify the process that has a lock on a particular file. I've searched through the Win32 API and WMI, but so far I can't find anything. I know it's possible - Sysinternals is able to list every resource accessed/locked by every process on the system.

Can anyone drop me a hint?

8条回答
我命由我不由天
2楼-- · 2019-01-23 13:51

WhoLockMe is a nice right click windows explorer extension.

查看更多
贪生不怕死
4楼-- · 2019-01-23 13:53

I don't know in Windows, but somebody might find useful to know that, in Linux, you can use the lsof command, or just search through the folders /proc/PROCESS_ID/fd and see what process has opened the file.

查看更多
祖国的老花朵
5楼-- · 2019-01-23 14:00

You can use handle.exe from Sysinternals.

Something like:

> handle /accepteula C:\path\to\directory
...
program.exe           pid: 1234   type: File           2E4: C:\path\to\directory
...

Thanks to https://stackoverflow.com/a/599268/367916 .

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-23 14:00

You could use Process Explorer from Microsoft

  1. Download & unpack & run Process Explorer
  2. Click Find menu and then click Find Handle or DLL... or press CTRL + F
  3. Copy and paste path to locked folder of file
  4. Click Search, you can kill process from main Process Explorer window
查看更多
\"骚年 ilove
7楼-- · 2019-01-23 14:00

This article might be helpful to you.

It appears you are forced to search through the list of files for each process on the system using undocumented functions in ntdll.dll.

查看更多
登录 后发表回答