如何监视文件系统的所有事件和活动 [英] How to monitor all events and activities of FileSystem

查看:118
本文介绍了如何监视文件系统的所有事件和活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:-D

如您所知,我们可以使用FileSystemWatcher类来监视目录或文件的事件.这些事件仅是创建",删除",更改",重命名",错误",我想监视所有事件的位置".例如,我想获取打开的目录或单击文件时的路径.类似于文件系统驱动程序,但在C#中.

那你对我有什么建议?

感谢:thumbsup:

Hi every one :-D

As you know we can use FileSystemWatcher class to monitor events of a directory or a file. The events are only Create, Delete, Change, Rename, Error, Dispose where as I want to monitor all events. For example I want to get the path of directory which is opened or when a file is clicked. Something like filesystem driver but in C#.

So what do you suggest me?

Thanks:thumbsup:

推荐答案

您可以轻松地监视鼠标和键盘的活动:
在C#中处理全局鼠标和键盘挂钩 [
What you can do easily is monitoring mouse and keyboard activity:
Processing Global Mouse and Keyboard Hooks in C#[^]

But what you are asking is not possible unless you hook into the process you are watching (dangerous and not to be recommanded).


我同意Olivier的观点.您需要结合使用FileSystemWatcher和全局挂钩.您将在没有任何同步的情况下从钩子和文件系统接收事件,因此很难弄清是什么点击导致了什么文件系统事件.另外,文件系统通知的时间安排也是一个问题.

请参阅以下文章:
FileSystemWatcher-纯混沌(第1部分,共2部分) [FileSystemWatcher-纯粹的混乱(第2部分,共2部分) [ ^ ].

如果您解释了设计的最终目标,则有可能获得更好的建议.您的方法看起来很奇怪.为什么要进行所有这些活动?

—SA
I agree with Olivier. You need to use combination of FileSystemWatcher and the global hook. You will receive events from hook and file system without any synchronization, so it will be very hard to figure out what click caused what file system event. Also, timing of the file system notification is an issue.

Please see these articles: FileSystemWatcher - Pure Chaos (Part 1 of 2)[^] and FileSystemWatcher - Pure Chaos (Part 2 of 2)[^].

If you explain ultimate goals of your design, chances are, you could get better advice. You approach looks strange. Why do you want all this activity?

—SA


FileSystemWatcher不跟踪单纯的文件打开.它仅跟踪对文件的物理更改(创建,更改,删除以及类似的操作).我唯一能想到的就是接近于执行您想要做的事情,就是维护系统中打开文件句柄的监视.您可能可以使用WMI或某些系统调试机制来获取该信息. Google是您的朋友.

编辑============

我在"c#文件句柄计数wmi"中找到了该搜索字词:

The FileSystemWatcher doesn''t track mere file opening. It just tracks physical changes to a file (create, change, delete, and that kind of thing). The only thing I can think of that will come close to doing what you want is to maintain a watch of open file handles in the system. You MIGHT be able to get that info using WMI, or some system debugging mechanism. Google is your friend.

EDIT ============

I found this googling for "c# file handle count wmi":

Listing Used Files[^]


这篇关于如何监视文件系统的所有事件和活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆