简体   繁体   English

目录名称 <Path> 无效| 模仿| Windows服务

[英]The directory name <Path> is invalid | Impersonation | Windows Service

I have a windows service which is intended to monitor a File Path and later perform some actions on the files created. 我有一个Windows服务,该服务旨在监视文件路径并稍后对创建的文件执行一些操作。

The location to be monitored is a network location on which the user I am impersonating has full access. 要监视的位置是我要模拟的用户对其具有完全访问权限的网络位置。

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;
}

I get an Error saying - "The directory name is invalid"... 我收到一条错误消息-“目录名称无效” ...

I have no clue what is causing this error, since the network path is accessible when I access it using the credentials manually. 我不知道是什么原因导致此错误,因为当我使用凭据手动访问网络路径时,可以访问它。

If you are trying to access resources on another server, then the account under which your code is running (not the impersonated account) should be configured to be able to delegate credentials. 如果您尝试访问另一台服务器上的资源,则应将运行代码的帐户(而不是模拟帐户)配置为能够委派凭据。

Check this MSDN article: Impersonation/Delegation 检查此MSDN文章: 模拟/委派

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM