Search code examples
c#windows-servicesnetworkcredentials

How to access to a shared resource with a windows service using local system user?


I need to access to a shared resource with a windows service using local system user. I have a try with the class UserImpersonation, but it only works in debugging. When I install my service, I can't access to a shared folder.

I have read about this topic, and I would like to know if the only way is to create an user with network credentials and execute the service with this user.


Solution

  • Your final paragraph of your question contains the answer. The service runs in the context of a specific user. You need to make sure that this user can access the resource in question. It's not uncommon to create dedicated users just for a particular service for this very reason.