Windows Service - UnauthorizedAccessException

隐身守侯 提交于 2019-12-23 01:18:34

问题


I have a Windows Service created in .NET 4.

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

"UnauthorizedAccessException was caught" - "Access to the path '(path)' is denied."

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


回答1:


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.



来源:https://stackoverflow.com/questions/8047656/windows-service-unauthorizedaccessexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!