文件/文件夹监控
监视磁盘文件活动的最佳方法是什么? 我的意思是获取完整的文件名(c:\ temp \ abc.txt),操作(创建/删除/修改/重命名),以及导致文件(多个)的用户(user1)和进程名称(notepad.exe)删除)活动。
我听说过一些 API 和 ShellNotifications,但无法使用它们来满足上述全部需求。
此致。
What is the best way to monitor disks against file activities. I mean that getting the full file name (c:\temp\abc.txt), action(created/deleted/modified/renamed), and also the user (user1) and process name (notepad.exe) causing the file (multiple delete) activities.
I heard about Some APIs and ShellNotifications but could not use them for the whole needs above.
Best regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最喜欢的博客之一很久以前就回答了这个问题(带有完整的源代码和演示应用程序)。 查看此处的 Delphi About.com 文章,其中有更深入的解释。 Zarko Gajic 在 http://delphi.about.com 提供的代码
希望在文件获取时收到通知在系统上创建、重命名或删除? 需要知道确切的文件夹和文件名? 让我们开始监视系统 shell 更改!
One of my favorite blogs answered this question (with full source and a demo application) quite a while ago. Checkout the Delphi About.com article here which has a more in depth explanation. Code provided by Zarko Gajic at http://delphi.about.com
Wanna get notified when a file gets created, renamed or deleted on the system? Need to know the exact folder and file name? Let's start monitoring system shell changes!
有一个 Windows API 用于接收有关目录及其子目录更改的通知,请参阅此SO 问题封装API的Delphi组件。
然而(据我所知)没有现成的界面来获取您需要的所有信息。 您当然可以监视目录,使用每个文件的所有可用信息填充文件列表,并将当前列表与先前列表进行比较,以确定更改的内容以及更改者。 然而,这不会扩展,并且无法获取所有信息 - 例如,您会看到文件已被删除,但我不认为您可以获得文件被删除的用户帐户的信息。
编辑:诸如Process Explorer之类的工具和朋友们提供了比通过 Windows API 提供的更多有关系统中发生的情况的信息,但他们通常需要驱动程序来访问此类信息,并且需要以管理员权限运行。
There is a Windows API to receive notifications about changes in directories and optionally subdirectories of that, see this SO question for a Delphi component encapsulating the API.
There is however (AFAIK) no ready interface to get all of the information you require. You could of course watch directories, populate lists of files with all the available information about each file, and compare the current list with the previous list to determine what changed and who did it. This will however not scale, and there will be no way to get all of the information - you will for example see that a file has been deleted, but I don't think you can get the info from which user account the file was deleted.
Edit: Tools like Process Explorer and friends provide a lot more information about what's going on in the system than is available via the Windows API, but often they need drivers to access that kind of information, and need to be run with admin privileges.
Stack Overflow 不允许我对 Mick 的回答发表评论。 我想让大家知道它只能在目标平台 Windows 32 位中编译。 如果你尝试使用 Windows 64 位目标平台编译它,它会抛出各种错误。
您可以在 Torry.net https://torry.net/pages.php 上找到原始源代码?id=252 在最底部的页面。
原始版本给了我一些错误,这些错误很小,但我修复了。
这是我编辑的适用于 Delphi 10.4.1 的版本(将此源代码放入 .pas 文件中并将其包含到新的包文件中。您将能够从那里编译并安装它。):
Stack Overflow won't let me comment on Mick's answer. I would like everyone to know that it only compiles in target platform windows 32bit. If you try to compile it using target platform windows 64 bit, it will throw all kinds of errors.
You can find the original source code on Torry.net https://torry.net/pages.php?id=252 on the very bottom page.
The original version gave me some errors, for which was minor, but I fixed.
Here's my edited version that works for Delphi 10.4.1 (put this source code in a .pas file and include it into a new package file. You'll be able to compile and install it from there.):
我有一些关于 Windows 的 Python 的东西,你可能会感兴趣
如果您愿意,可以从以下位置移植: http://github.com/gorakhargosh/watchdog
I have something in Python for Windows which you might be interested
to port from if you like: http://github.com/gorakhargosh/watchdog