Windows service can't copy to file share

半城伤御伤魂 提交于 2019-12-03 16:05:00

It ended up being a permissions issue - after running the service as a different user that was setup on the samba share it ran without a problem, copying files across.

Still don't understand why when using a different account I could copy/create files on the share using windows explorer but when the service was running under the same account it couldn't access the share at all :(

I would recommend mapping a drive first and then doing the file copy to the mapped drive instead of the share.

You can map a drive using the dos net use command. For example:

System.Diagnostics.Process.Start("net", "use h: \remoteserver\shareddir /User:domian\me password")

This should resolve any login issues.

A very helpful tool in your situation is process monitor. Just run it as administrator and add the following filter:

Process Name is "your_process.exe" AND Operation is "CreateFile"

You will see detailed information about the files your process is trying to use.

As mentioned, when I log in with the same account that the service is running as, I have no problems copying to and creating files on the share. – Oded 1 min ago

Did you grant the user account the service is running as "Logon as Service" permissions in the local security policy??

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