【问题标题】:The directory name <Path> is invalid | Impersonation | Windows Service目录名称 <路径> 无效 |冒充 |视窗服务
【发布时间】: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


    【解决方案1】:

    如果您尝试访问另一台服务器上的资源,则运行代码的帐户(不是模拟帐户)应配置为能够委派凭据。

    查看这篇 MSDN 文章:Impersonation/Delegation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      相关资源
      最近更新 更多