Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 files locked for reading: how to find out who's locking them

In C++ (specifically on Visual C++), sometimes you cannot open a file because another executable has it opened and is not sharing it for reads. If I try to open such a file, how can I programatically find out who's locking the file?

like image 386
Warpin Avatar asked Jan 02 '10 03:01

Warpin


People also ask

How do you find who is locking a file Windows?

In the Resource Monitor window, go to the CPU tab and expand the Associated Handles option. Now, in the search box, type the name of the file that is showing locked by a process and press Enter button. It will show you a list of processes holding the target file.

What is locking my file?

File locking is a feature that prevents a file from being edited. This allows teams and collaborators to coordinate who is editing a file and avoid conflicted copies. If a file is locked, those who have access to the file will still be able to view, comment on, and share a link to the file.


1 Answers

In Windows 2000 and higher, you cannot do this without using a kernel-mode driver. Process Explorer and other similar tools load a driver automatically to accomplish this. This is because the file handles are in kernel space and not accessible by user-mode applications (EXE files).

If you are really interested in doing this, take a look at this project.

like image 98
Dumb Guy Avatar answered Sep 28 '22 00:09

Dumb Guy