Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C语言中访问服务器路径_C#_Windows_File_Service_Windows Services - Fatal编程技术网

C# 在C语言中访问服务器路径

C# 在C语言中访问服务器路径,c#,windows,file,service,windows-services,C#,Windows,File,Service,Windows Services,我需要将文件从服务器路径复制到本地路径。下面是我用来访问服务器路径的C代码 NetworkCredential ntCredential = new NetworkCredential(User, Password); CredentialCache cCredential = new CredentialCache(); cCredential.Add(new Uri(Server), "Basic", ntCredential); DirectoryInfo d = new Dire

我需要将文件从服务器路径复制到本地路径。下面是我用来访问服务器路径的C代码

 NetworkCredential ntCredential = new NetworkCredential(User, Password);
 CredentialCache cCredential = new CredentialCache();
 cCredential.Add(new Uri(Server), "Basic", ntCredential);
 DirectoryInfo d = new DirectoryInfo(ServerPath);
 FileInfo[] filelistinfo = d.GetFiles();
如果我将其创建为普通的控制台应用程序,则该代码可以正常工作。但如果我在Windows服务中使用相同的代码,则会引发错误登录失败:未知用户名或错误密码。 我将服务器路径指定为\vmmson\Data\
有人帮我解决这个问题。

您的服务运行的用户是什么?我的服务运行的用户是本地系统帐户。我还尝试在网络服务帐户上运行该服务。但我也犯了同样的错误。