简体   繁体   English

为什么我不能从Windows服务中找到此UNC路径?

[英]Why can't I hit this UNC path from my Windows Service?

I'm working on file replication service in C#. 我正在使用C#开发文件复制服务。 The service works perfectly in an environment where I have access to the user space; 该服务在我可以访问用户空间的环境中运行良好; however, when I run it as a service I start encountering errors. 但是,当我将其作为服务运行时,我开始遇到错误。

There is a lot of information out on accessing UNC shares in this scenario, but after pursuing what seemed to be the most likely solution, I've still come up short. 在这种情况下,有关访问UNC共享的信息很多,但是在寻求似乎最有可能的解决方案之后,我仍然很简短。

In my 'faulty' environment, the service is running as the 'administrator' account, and I've taken a couple of approaches; 在我的“故障”环境中,该服务以“管理员”帐户的身份运行,并且我采取了几种方法。 both using a mapped network drive, and a specific UNC share, and end up with the same outcome in both circumstances. 两者都使用映射的网络驱动器和特定的UNC共享,并且在两种情况下最终都具有相同的结果。

My constructor contains the logic for detection of whether or not the file exists, so it should be the only relevant piece in this equation; 我的构造函数包含用于检测文件是否存在的逻辑,因此它应该是该方程式中唯一相关的部分。

    public FileMonitor(String TargetPath)
        : base()
    {
        if (String.IsNullOrEmpty(TargetPath))
        {
            throw new ArgumentNullException("Cannot instantiate FilesystemMonitor. TargetPath was not provided or is null.");
        }
        else
        {
            this.FileCache = new Dictionary<string, DateTime>();

            if (Directory.Exists(TargetPath))
            {
                this.TargetDirectory = new DirectoryInfo(TargetPath);
                return;
            }
            else if (File.Exists(TargetPath))
            {
                this.TargetFile = new FileInfo(TargetPath);
                return;
            }
            else
            {
                if (TargetPath.StartsWith("\\\\"))
                {
                    FileInfo Finfo = new FileInfo(TargetPath);

                    UNCHandler.connectToRemote(Finfo.DirectoryName, "administrator", "password");

                    if (Directory.Exists(TargetPath))
                    {
                        this.TargetDirectory = new DirectoryInfo(TargetPath);
                        return;
                    }
                    else if (File.Exists(TargetPath))
                    {
                        this.TargetFile = new FileInfo(TargetPath);
                        return;
                    }
                    else
                    {
                        throw new InvalidOperationException("Cannot instantiate FileMonitor for file that does not exist at " + TargetPath + ".");
                    }
                }
                else
                {
                    throw new InvalidOperationException("Cannot instantiate FileMonitor for file that does not exist at " + TargetPath + ".");
                }
            }
        }
    }

The only exception to my last statement is the potential necessity of knowing what my UNCHandler class does - but to quell that storm, it is an exact rip from the answer Found Here 我上一条语句的唯一例外是可能有必要知道UNCHandler类的功能-但要平息这场风暴,这是从“ 找到这里”的答案中得到的确切答案。

To be clear - the issue here is that the File.Exists and Directory.Exists checks fail, even after an attempt to connect to the remote system. 需要明确的是,这里的问题是即使尝试连接到远程系统后,File.Exists和Directory.Exists检查也会失败。

My error log hands me back the following; 我的错误日志让我退回了以下内容; 'system|ReadConfiguration:Cannot instantiate FileMonitor for file that does not exist at Z:.' 'system | ReadConfiguration:无法实例化Z:处不存在的文件的FileMonitor。' - which is effectively the exception that I generate in the above constructor. -这实际上是我在上述构造函数中生成的异常。

I've tried using a variety of methods to reach my 'source'; 我尝试使用各种方法来达到我的“来源”。 including using a UNC share and a mapped drive, only to yield no difference in results. 包括使用UNC共享和映射的驱动器,仅使结果无差异。

I took an answers advice and ran microsoft's Process Monitor in an attempt to look further into this, but have yet to find any information in this venue that will help me. 我接受了一个答案建议,并运行了Microsoft的Process Monitor,试图对此做进一步的研究,但还没有在该场所找到任何对我有帮助的信息。 Under my process, I get dozens of SUCCESS's until I attempt to reach the share - at which point the only indicative results are a 'NAME NOT FOUND' against a CreateFile operation, and a 'FILE LOCKED WITH ONLY READERS' moments later against a 'CreateFileMapping' call. 在我的过程中,我获得了数十次成功,直到尝试达到份额为止。在这一点上,唯一的指示性结果是针对CreateFile操作的“名称未找到”,以及稍后针对“文件未锁定的文件”。 CreateFileMapping”调用。

The process is running as the local systems Administrator account, and in my 'user space' I have a mapped drive to the same location I am trying to reach, that I can manipulate fully. 该进程以本地系统管理员帐户的身份运行,在我的“用户空间”中,我有一个映射的驱动器到我要访问的相同位置,可以完全操作。

What error are you getting? 你遇到了什么错误? Have you tried running ProcessMonitor ( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx ) to see what is happening? 您是否尝试过运行ProcessMonitor( http://technet.microsoft.com/zh-cn/sysinternals/bb896645.aspx )以查看发生了什么情况? Are you running as the local administrator for that computer? 您是否以该计算机的本地管理员身份运行? Does that local administrator account actually have access to the share in question? 该本地管理员帐户实际上是否有权访问所讨论的共享? Have you tried using psexec ( http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx ) to run a command shell as that user and see if you actually have access to that share? 您是否尝试过使用psexec( http://technet.microsoft.com/zh-cn/sysinternals/bb897553.aspx )以该用户身份运行命令外壳,并查看您是否实际上有权访问该共享?

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

相关问题 为什么我不能从机器外部打我的WCF服务,但我可以在本地? - Why can't I hit my WCF service from the outside of the machine, but I can locally? 我可以通过代码获取网络驱动器的UNC路径吗? - Can I get UNC path of a network drive through my code? 我无法从C#访问unc路径。 获取访问权限被拒绝 - I can't access unc path from C#. Getting access is denied 为什么我不能安装我的 windows 服务 - 指定的服务已经存在 - Why can't I install my windows service - Specified service already exists Windows 服务无法访问。网络位置 (UNC) 路径 - Windows Service cannot access network location (UNC) Path 我如何弄清楚为什么Windows Service中的计时器事件没有触发? - How can I figured out why the timer event in my Windows Service isn't firing? 为什么我的Windows服务无法执行外部应用程序? - Why my Windows Service can't execute an external application? 发布项目时能否将C:\\ Program Files用作UNC路径 - Can I use C:\Program Files as the UNC path when publishing my project 当我运行 Windows 窗体应用程序时,为什么我的 if 语句和 MessageBox 没有被点击或显示? - Why aren't my if statements and MessageBox's not getting hit or displayed when I run my Windows form applications? 为什么我不能使用NetworkService帐户从Windows服务中打印图表? - Why can't I print a chart from a windows service using NetworkService account?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM