目录名<path>无效|假冒| Windows服务</path>

时间:2014-02-18 06:55:16

标签: c# c#-4.0 windows-services impersonation filesystemwatcher

我有一个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;
}

我收到错误说 - “目录名无效”...

我不知道导致此错误的原因,因为当我手动使用凭据访问网络路径时,可以访问网络路径。

1 个答案:

答案 0 :(得分:1)

如果您尝试访问其他服务器上的资源,则应将运行代码的帐户(而非模拟帐户)配置为能够委派凭据。

查看此MSDN文章:Impersonation/Delegation