tags:

views:

79

answers:

3

I'm looking for a way to monitor which processes are using (or attempting to access) a file over a duration of time. What are some good Windows APIs or tools to achieve this?

A: 

You can use the FileSystemWatcher.

Here's a nice tut. http://www.geekpedia.com/tutorial173_File-monitoring-using-FileSystemWatcher.html

JeremySpouken
+2  A: 

FileSystemWatcher is not suitable for determining the process.

There already was a different question. look here, this solution fits your needs.

henchman
That seems to be related to file locking, and takes a snapshot. So it can't tell who accessed a file without locking, and it would require polling.
MSalters
+1  A: 

You could replace the file by a reparse point. The reparse point invokes a custom file system filter, which can redirect the access to anothe file. This is for instance how NTFS junctions work. If you let your file system filter handle reparse points in the same way, you can intercept all attempts by all processes to open the underlying file. It's a rather heavy-handed approach though, as it involves modifying the file system itself.

MSalters