.NET FileSystemWatcher的更改事件MSDN文档说:
当对监视目录中的文件或目录的大小、系统属性、最后写入时间、最后访问时间或安全权限进行更改时,会引发更改事件。
但是,当我试图使用这个类来捕获对目录或文件的NTFS安全更改时,更改的事件永远不会触发。
有没有办法在没有投票的情况下完成这个任务?
发布于 2011-06-22 02:09:41
FileSystemWatcher确实会观察安全权限的变化。
在设置NotifyFilters.Security时,需要包括FileSystemWatcher.NotifyFilter标志。我尝试了下面的代码,更改了Temp文件夹中一个文件的权限。触发了Changed事件。
public static void Main()
{
var fileSystemWatcher = new FileSystemWatcher("C:\\Temp", "*.*");
fileSystemWatcher.NotifyFilter = NotifyFilters.Security;
fileSystemWatcher.Changed += fileSystemWatcher_Changed;
fileSystemWatcher.EnableRaisingEvents = true;
Thread.Sleep(-1);
}
private static void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
}https://stackoverflow.com/questions/6433805
复制相似问题