FileSystemWatcher – LastAccess Not Working

To have System.IO.FileSystemWatcher LastAccess work, the system must have access logging enabled with the following command.

fsutil behavior set DisableLastAccess 0

After setting this, reboot, and you can successfully use the FileSystemWatcher to monitor LastAccess of files (sorta).

Example Code

FileSystemWatcher lWatcher = new FileSystemWatcher(@"C:\windows\temp", "*.*");
                lWatcher.NotifyFilter = NotifyFilters.LastAccess;
                lWatcher.EnableRaisingEvents = true;
                lWatcher.Changed += new FileSystemEventHandler(HandlerWatcherChanged);
                lWatcher.IncludeSubdirectories = true;
        static void HandlerWatcherChanged(object sender, FileSystemEventArgs e)
            Console.WriteLine("[" + DateTime.Now.ToString() + "] ACCESS " + e.FullPath.ToString());


Leave a Reply

Your email address will not be published. Required fields are marked *