C# 监控文件/目录访问
我想开发一个记录机器上访问的文件/目录的应用程序。
例如,我转到 D:\ 并进入文件夹 Documents 并打开一个 Word 文件。我希望我的应用程序以以下格式创建日志:
- D:\ Opened
- D:\documents Opened
- D:\documents\secret.docx Opened
我使用 FileSystemWatcher 来实现其他类型的文件系统活动,但无法获取事件用于访问此。
I want to develop the application which logs the files / directories accessed on the machine.
e.g. I go to D:\ and into a folder documents and open a word file. I want my application to create a log in the following format:
- D:\ Opened
- D:\documents Opened
- D:\documents\secret.docx Opened
I've used FileSystemWatcher to achieve the other type of file system activity but unable to get events for accessing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你想做一个像 sys 内部结构这样的 FileMon 程序。 Mark 在他们的网站上讲述了 FileMon 的工作方式,因此您可以通过阅读本文获得一些灵感。
另请参阅此处: 如何通过用户名监控文件服务器上的文件访问和更改?
sounds like you wanna do a FileMon program like sys internals. in their website Mark tells about the way FileMon works so you can get some inspiration by reading the article.
also see here: How do you monitor file access and changes on a file server by user name?
不确定可以使用 filesystemwatcher 实现这种监视,因为我相信它的目的是监视更改。您可以使用文件系统审核(通过进入高级安全设置),它将在事件日志中记录事件,您可以从那里提取它。
Not sure this sort of monitoring can be achieved with filesystemwatcher as it is aimed at monitoring changes I believe. You could use filesystem Auditing (by going into advanced security settings) which will log events in eventlog and you can pull it from there.
最可行的选择是使用文件系统过滤器驱动程序。此类驱动程序使您可以对发送到特定文件系统的所有请求进行细粒度控制。这种方法的唯一问题是在内核模式下开发此类驱动程序的复杂性。
Most viable option is use of file system filter driver. Such driver gives you fine-grain control over all requests going to particular file system. The only issue with this approach is complexity of developing such driver in kernel mode.