为什么System.IO.File.Copy不起作用? [英] Why System.IO.File.Copy is not working?

查看:290
本文介绍了为什么System.IO.File.Copy不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个Windows服务,创建了一个文件,我想将此文件移动到另一台PC。

在目标PC中我创建了一个文件夹并分享它并且也适用于完全正确。

当我从命令提示符复制文件时它是工作文件。但在我的.net代码中,它给了我一个Access denid的错误。这两台PC都包含Windows Server 2008操作系统。

i的编写代码如

Hello all,
I have create one Windows service which create one file and i want to move this file to another PC.
In Destination PC i have create one folder and share it and also apply full right.
When i copy file from Command prompt it's working file. But in my .net code it's give me error for Access denid. Both PC contain Windows Server 2008 OS.
i have write code like

System.IO.File.Copy(strSourcepath,strDestPath,true);





请帮我解释为什么会出错。



Please help me why this give error.

推荐答案

可能,这是一个权限问题。



当您从命令行执行文件复制时,您将以登录用户身份运行它:所以使用目标文件夹进行访问用户权限。

当您的服务运行时,它不会以普通用户身份运行 - 因为在启动服务时没有用户登录 - 因此它获取了不同的权限。

您需要将服务分配给特定帐户,或者为目标文件夹提供适当的访问权限。
Probably, it's a permissions problem.

When you do a file copy from the command line, you are running it as the logged in user: so the destination folder is accessed using the user permissions.
When your service runs, it does not run as a "normal" user - because no user has been logged in when the services are started - so it acquires different permissions.
You either need to assign the service to a particular account, or give appropriate access permissions to your destination folder.


这篇关于为什么System.IO.File.Copy不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆