FileSystemWatcher-目标目录所需的最低权限? [英] FileSystemWatcher - minimum permissions needed on target directories?
问题描述
使用.NET FileSystemWatcher http://msdn.microsoft .com/en-us/library/system.io.filesystemwatcher.aspx 来监视目录中包含以下内容的文件:已更改;已更改.已创建;已删除;重命名事件.
Using the .NET FileSystemWatcher http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx to monitor a directory full of files for : Changed; Created; Deleted; Renamed events .
运行FileSystemWatcher的帐户对其所监视的目录所拥有的最低权限是多少?
What's the minimum the rights the Account running the FileSystemWatcher needs over the directory it's watching ?
似乎应该是READ,但我在任何地方都找不到该文件.
It seems like it would be READ but I can't find that documented anywhere.
谢谢
推荐答案
基础API是ReadDirectoryChangesW. MSDN Library文章中唯一提到的是目录句柄需要FILE_LIST_DIRECTORY访问权限,并且需要使用FILE_FLAG_BACKUP_SEMANTICS选项打开目录.
The underlying API is ReadDirectoryChangesW. The only thing mentioned in the MSDN Library article for it is that the FILE_LIST_DIRECTORY access right is required on the directory handle and the directory needs to be opened with the FILE_FLAG_BACKUP_SEMANTICS option.
.NET框架代码通常很有帮助.私有FileSystemWatcher.StartRaisingEvents()方法使用以下代码打开目录句柄:
The .NET framework code is often helpful. The private FileSystemWatcher.StartRaisingEvents() method uses this code to open the directory handle:
directoryHandle = NativeMethods.CreateFile(
directory, // Directory name
UnsafeNativeMethods.FILE_LIST_DIRECTORY, // access (read-write) mode
UnsafeNativeMethods.FILE_SHARE_READ |
UnsafeNativeMethods.FILE_SHARE_DELETE |
UnsafeNativeMethods.FILE_SHARE_WRITE, // share mode
null, // security descriptor
UnsafeNativeMethods.OPEN_EXISTING, // how to create
UnsafeNativeMethods.FILE_FLAG_BACKUP_SEMANTICS |
UnsafeNativeMethods.FILE_FLAG_OVERLAPPED, // file attributes
new SafeFileHandle(IntPtr.Zero, false)); // file with attributes to copy
仅将FILE_FLAG_OVERLAPPED用于异步通知.
Use FILE_FLAG_OVERLAPPED only for asynchronous notifications.
这篇关于FileSystemWatcher-目标目录所需的最低权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!