Coder Social home page Coder Social logo

minifswatcher's Introduction

MiniFSWatcher

MiniFSWatcher is a file system event watcher for C# based on the minispy driver example from Microsoft. Compared to the default FileSystemWatcher class, MiniFSWatcher provides the following benefits:

Capturing file moved events

The default FileSystemWatcher has no notion of moved files, it'll only generate "created" and "deleted" events instead. MiniFSWatcher will let you track file movement within one partition.

Reducing the amount of changed events

With the AggregateEvents option, you'll only receive one file event when the respective file handle is closed and thus no more consecutive changes will occure. If multiple write operations were performed, only one "changed" event is triggered. If a file is created and changed (i.e. due to a copy operation), you'll only receive one "created" event.

Getting information about the process causing the change

Sometimes it is useful to know who caused the change, for example to ignore changes performed by a certain application. MiniFSWatcher provides the ID of the causing process with every event and further allows to directly filter out all events caused by its own process ID.

Usage

The following example shows how to use MiniFSWatcher to watch a directory and all subdirectories.

var eventWatcher = new EventWatcher();

eventWatcher.OnRenameOrMove += (filename, oldFilename, process) =>
{
  Console.WriteLine("File " + oldFilename + " has been moved to " + filename + " by process " + process );
};

eventWatcher.Connect();
eventWatcher.WatchPath("C:\\Users\\MyUser\\*");

Installation

MiniFSWatcher consists of a user mode C# library and a minifilter driver running in kernel mode. Both components need to be installed to observe file system events.

Installing the user mode library

You can install the user mode library from nuget or simply add the MiniFSWatcher project to your project references.

Installing the kernel mode driver

The kernel driver needs to be compiled and installed manually. Therefore, make sure you have the Windows Driver Kit (WDK) 10 installed. After compiling the driver with VS, you can install the driver with the following command

 RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 132 ./minifswatcher.inf

The driver will be loaded automatically after reboot. To load it manually without reboot, run

 fltmc.exe load minifswatcher

If you don't have a valid code signing certificate and try to install the driver on 64bit Windows, you need to enable test signed drivers as described here.

Please make sure to always compile and install the correct driver version (32/64bit) depending on your operating system!

To uninstall the driver, run

RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultUninstall 132 ./minifswatcher.inf

minifswatcher's People

Contributors

zalintyre avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.