Win32 files locked for reading: how to find out wh

2019-01-19 03:39发布

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?

2条回答
叛逆
2楼-- · 2019-01-19 04:02

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.

查看更多
太酷不给撩
3楼-- · 2019-01-19 04:04

The MSDN approved way is IFileIsInUse::GetAppName(). Requires Vista, though.

查看更多
登录 后发表回答