【发布时间】:2012-04-13 02:41:01
【问题描述】:
我有一个 Windows 服务,它轮询特定文件夹以创建新文件。当文件夹位于本地驱动器之一(例如 C: 或 D: 该服务无法在映射驱动器上找到文件夹。
这是在轮询之前检查文件夹是否存在的代码:
System.Security.Principal.WindowsIdentity userIdentity =
System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal principal =
new System.Security.Principal.WindowsPrincipal(userIdentity);
MappedDriveResolver mdr = new MappedDriveResolver();
if (mdr.isNetworkDrive(folderPath))
{
LoggingAppWrapper.LogDeveloperMessage(folderPath + " is on a Mapped drive", 1, TraceEventType.Information, string.Empty);
}
MappedDriveResolver 是我在这里找到的一个类How do I determine a mapped drive's actual path?
该链接中的代码在简单的控制台应用程序中运行良好,但当它是 Windows 服务的一部分时会失败。 有什么建议可以让代码为 Windows 服务工作吗?
问候。
【问题讨论】:
-
您确定执行服务的帐户具有适当的权限?
-
我认为这个答案会对您有所帮助:[线程“映射要由服务使用的网络驱动器”的答案][1] [1]:stackoverflow.com/a/4763324/3860297
标签: c#