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条回答
Summer. ? 凉城
2楼-- · 2019-01-23 14:07

If you can limit yourself to new enough versions of Windows, the Restart Manager can tell you which process has a particular file open.

查看更多
唯我独甜
3楼-- · 2019-01-23 14:10

Because of the way Process Explorer works, I suspect that what you need to look for is a way of finding the file handles attached to a given process, and that you'll have to pull that list for each process in the system and look for your file within it.

查看更多
登录 后发表回答