繁体   English   中英

使用WindowService(以NetworkService运行)将文件从一个文件夹移动到另一个文件夹的问题

[英]Issue to move file from one folder to another using window service, running as NetworkService

我想在启动Windows服务时将.txt文件从一个文件夹移动到另一个文件夹。

protected override void OnStart()
    {
        string sourceFile = @"d:\Source\file.txt";
        string destinationFile = @"D:\Destination\file.txt";
        File.Move(sourceFile, destinationFile);
    }

serviceProcessInstaller1 Accunt类型为LocalSystem时,此代码运行良好。 如果我将serviceProcessInstaller1 Accunt类型更改为NetworkService ,我将得到错误的访问,该路径被拒绝 帮我解决这个问题?

您的问题是计算机中的用户权限。 尝试更改文件和文件夹的权限,并设置较少的限制。 我确定,如果您为所有用户设置了所有权限,则您的服务将正常运行。 但这也是冒险的。

此页面的 “文件访问”部分,您可以阅读如何配置此权限。

暂无
暂无

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

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