Ale*_*xPi 2 .net c# security filesystemwatcher ntfs
.NET FileSystemWatcher的Changed事件MSDN文档说:
当对正在监视的目录中的文件或目录的大小,系统属性,上次写入时间,上次访问时间或安全权限进行更改时,将引发Changed事件.
但是,当我尝试使用此类捕获对目录或文件的NTFS安全更改时,Changed事件永远不会触发.
有没有一些方法可以在没有民意调查的情况下完成
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)
{
}
Run Code Online (Sandbox Code Playgroud)