如何使用Dokan库跟踪文件? [英] How to use Dokan Library to trace File?

查看:580
本文介绍了如何使用Dokan库跟踪文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要跟踪文件(例如C:\ test.txt).当对此文件执行操作时,例如编辑,修改,读取...,我想将操作写入日志文件.该怎么做?
我认为应该使用Dokan Library.但是我不确定.请帮我.

i want to trace a file (ex C:\test.txt). When have an action on this file such as edit, modify, read, ... i want to write action to logfile. How to do that?
I think should be using Dokan Library. But i''m not sure about it. Please help me. Thanks!

推荐答案

您可以从.NET Framework的System.IO命名空间中使用FileSystemWatcher类.以下是代码段:
You can use FileSystemWatcher class from System.IO namespace of .NET framework. Herez the code snippet:
public class MyFileWatcher
{
    public static void Main()
    {
    Run();
    }

    [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public static void Run()
    {
        // Create a new FileSystemWatcher and set its properties.
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = @"c:\test.txt";
        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;

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

        // Begin watching.
        watcher.EnableRaisingEvents = true;

        while(Console.Read()!='q');
    }

    // Define the event handlers.
    private static void OnChanged(Object source,FileSystemEventArgs e)
    {
    .............
    }


可以使用.NET中的FileSystemWatcher或文件系统 filter 驱动程序(您已将其与文件系统驱动程序混淆)来监视文件操作.唯一的用户模式解决方案(基于内核模式驱动程序)是 CallbackFilter .
File operations can be monitored either using FileSystemWatcher in .NET or using file system filter driver (which you have confused with a filesystem driver). The only user-mode solution (based on kernel-mode driver) is CallbackFilter.


这篇关于如何使用Dokan库跟踪文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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