简体   繁体   中英

Programmatically monitor files on Windows

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?

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.

You can use the FileSystemWatcher.

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

FileSystemWatcher is not suitable for determining the process.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM