-1

I am looking for something that detects when a user opens a file(much like anti-virus software), i've been looking, but all i could find is when a user creates/deletes/modifies a file on a specific path

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
stefan
  • 165
  • 1
  • 15

2 Answers2

-1

You can use C# FileWatcher - Listens to the file system change notifications and raises events when a directory, or file in a directory, changes.

Example: http://matijabozicevic.com/blog/csharp-net-development/csharp-monitor-directory-activity-using-fileSystemWatcher-class

Using FileSystemWatcher to monitor a directory

MSDN: https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

FileSystemWatcher watcher;

private void watch()
{
   watcher = new FileSystemWatcher();
  watcher.Path = path;
  watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                     | NotifyFilters.FileName | NotifyFilters.DirectoryName;
  watcher.Filter = "*.*";
  watcher.Changed += new FileSystemEventHandler(OnChanged);
  watcher.EnableRaisingEvents = true;
}

private void OnChanged(object source, FileSystemEventArgs e)
{
  //Copies file to another directory.
}
Community
  • 1
  • 1
null1941
  • 972
  • 8
  • 20
-1

Try using the FileSystemWatcher.Changed event: https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed(v=vs.110).aspx

In order to detect when it is opened, you must set the NotifyFilter property to NotifyFilters.LastAccess (this will trigger the Changed event because the LastAccess property of the file is changed).

I've never used it to monitor an entire HDD, so YMMV.

solidau
  • 4,021
  • 3
  • 24
  • 45