[英].NET FileSystemWatcher to detect NTFS security changes
The .NET FileSystemWatcher's Changed event MSDN documentation says: .NET FileSystemWatcher的Changed事件MSDN文档说:
The Changed event is raised when changes are made to the size, system attributes, last write time, last access time, or security permissions of a file or directory in the directory being monitored.
对受监视目录中的文件或目录的大小,系统属性,上次写入时间,上次访问时间或安全权限进行更改时,将引发Changed事件。
However, when I try to use this class to capture NTFS security changes to a directory or a file the Changed event never fires. 但是,当我尝试使用此类捕获NTFS安全性更改到目录或文件时,Changed事件从不触发。
Is there some way of accomplishing this without polling? 有没有某种方法可以完成此任务而无需轮询?
FileSystemWatcher
does watch security permissions changes. FileSystemWatcher
确实监视安全权限更改。
You need to include NotifyFilters.Security
flag, when you set FileSystemWatcher.NotifyFilter
. 设置
FileSystemWatcher.NotifyFilter
时,需要包括NotifyFilters.Security
标志。 I tried the code below, changed permissions for a file in Temp
folder. 我尝试了下面的代码,更改了
Temp
文件夹中文件的权限。 The Changed
event was triggered. Changed
触发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)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.