gpt4 book ai didi

c# - 读取文件时引发事件?

转载 作者:行者123 更新时间:2023-11-30 18:08:57 25 4
gpt4 key购买 nike

我有外部应用程序读取文件,我想 Hook 它以在我的应用程序中获取事件。但我找不到 Hook ReadFile 的源(或其他可以帮助我实现这一目标的东西)。有什么想法如何做到这一点吗?它必须在用户模式下完成。我正在考虑类似进程监视器的东西。我想知道它是如何做到的..

最佳答案

在 .net 中,您可以使用 FileSystemWatcher 。您需要为 Changed 添加处理程序事件将检测上次访问时间的变化(除其他外)。

来自上面链接的 MSDN 示例:

public static void Foo()
{
// Create a new FileSystemWatcher and set its properties.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"Your path";
/* Watch for changes in LastAccess time */
watcher.NotifyFilter = NotifyFilters.LastAccess;
// Only watch text files.
watcher.Filter = "*.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);

// Begin watching.
watcher.EnableRaisingEvents = true;
}

private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}

关于c# - 读取文件时引发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com