I have external app reading files, I want to hook that to get event in my app. But I cannot find a sources hooking ReadFile (or something else that can help me achieve that). Any ideas how to do that? It must be done in User-Mode. I was thinking for something similar to Process Monitor. I wonder how it does it..
In .net you can use the FileSystemWatcher . You will need to add a handler for the Changed event which will detect a change in the last access time (amongst other things).
From the MSDN example linked above:
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.