You can use IFileIsInUse and GetInfoForFileInUse
I had posted a sample in VB in this thread : How to kill the process which is accessing an image file, so I can delete it in WinForms App.
For SystemHandleInformation, I had posted a sample in C++ in this thread : Finding process holding device reference
How to determine the process of accessing it according to the file name
I want to implement a function that can determine the process accessing it according to the file name。
I found two implementation methods on the network。
1.Use the NtQuerySystemInformation function to find all handles, then filter out file handles from all handles and get the file name.
--However, the instructions for SystemHandleInformation were not found in the NtQuerySystemInformation API doc。
--There seems to be no definition in the SDK header file
2.It seems that I can use Restart Manager to register the file name and get the name of the process or service accessing the file to achieve this effect.
--But I seem to need to use the dynamic link library file rstrtmgr.dll,
--I don't have this DLL in my system, and I can't find a DLL that can be used. I once downloaded one, but when I use it, I am prompted that with "skipping incompatible.. / rstrtmgr.dll when searching for - lrstrtmgr"
Finally, I found the handle.exe tool in Doc / sysinternals, but I don't know how to achieve this effect.
Or there are other ways to enumerate the handles of running processes.
Can someone help me……
Thank you very much! ☆⌒(´▽`)v THX!!
2 answers
Sort by: Most helpful
-
Castorix31 81,741 Reputation points
2021-11-29T08:13:48.777+00:00 -
Xiaopo Yang - MSFT 11,496 Reputation points Microsoft Vendor
2021-12-02T05:54:03.343+00:00 I also found two answers. 1. How to find all processes using a device 2. Get the process which has specific handle of a file(using NtQueryInformationFile, a little tricky)