Windows 服务 - UnauthorizedAccessException [英] Windows Service - UnauthorizedAccessException

查看:21
本文介绍了Windows 服务 - UnauthorizedAccessException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .NET 4 中创建了一个 Windows 服务.

I have a Windows Service created in .NET 4.

我需要从另一个服务器访问文件,但出现异常:

I need to access a file from antoher server and I get an exception:

UnauthorizedAccessException 被捕获" - 对路径 '(path)' 的访问被拒绝."

如果我创建一个访问该文件的新 Windows 窗体应用程序,它就可以工作.Windows 服务作为本地系统运行.

If I make a new Windows Forms application which accessed that file, it works. The Windows Service runs as Local System.

推荐答案

显然您的计算机帐户没有访问远程文件共享的权限.您必须在文件共享级别和文件系统级别授予计算机帐户 \$ 的权限.对于共享权限,使用 fsmgmt.msc,对于文件系统,您可以使用 cacls 命令来实现.另一种解决方案是模拟一个已经对该目录具有权限的有效用户帐户.

Apparently your machine account does not have permissions to access remote file share. You have to grant rights to the machine account <DOMAIN>\<machine_name>$ on both file share level as well as file system level. For share permissions use fsmgmt.msc, for file system you can do it using cacls command. Alternative solution is to impersonate a valid user account that already has permission to this directory.

这篇关于Windows 服务 - UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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