【发布时间】:2014-03-17 18:27:24
【问题描述】:
我有一个 Windows 服务,旨在监视文件路径,然后对创建的文件执行一些操作。
要监控的位置是我模拟的用户拥有完全访问权限的网络位置。
LOGON32_LOGON_INTERACTIVE = 3;
LOGON32_PROVIDER_DEFAULT = 0;
string watchPath = @"\\servername\Folder\";
using (new Impersonator("UserName", "Domain", "Password"))
{
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
FSWatcher = new FileSystemWatcher();
FSWatcher.Path = watchPath; \\ POINT OF ERROR
FSWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
FSWatcher.Filter = "*.xls";
FSWatcher.Created += new FileSystemEventHandler(OnChanged);
FSWatcher.EnableRaisingEvents = true;
FSWatcher.IncludeSubdirectories = false;
}
我收到一条错误消息 - “目录名称无效”...
我不知道是什么导致了这个错误,因为当我使用凭据手动访问网络路径时可以访问它。
【问题讨论】:
标签: c# c#-4.0 windows-services impersonation filesystemwatcher