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?
A:
Use the Process Explorer http://download.cnet.com/Process-Explorer/3000-2094_4-10223605.html
Es ist fantastisch!
Hamish Grubijan
2010-01-02 03:45:04
i believe he's looking for a programmatic way to this
Matt Joiner
2010-01-02 05:07:28
+7
A:
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.
Dumb Guy
2010-01-02 03:46:57
You can see that Process Explorer is loading a driver by looking at the DLLs of the `System` process; you will see a driver similar to `PROCEXP113.SYS` loaded
Dumb Guy
2010-01-02 03:53:06
A:
The MSDN approved way is IFileIsInUse::GetAppName()
. Requires Vista, though.
MSalters
2010-01-04 15:23:50