Tuesday, September 11, 2007

Accessing network resource with in a Windows Service

Recently I ran into this problem where my windows service running under local system account could not access network resources such as shared folders. After googling a bit, I found Microsoft article that recommended running the service under "Network Service" account instead of System account when the service requires access to network resources. That sounds reasonable.

After applying the changes run my service under Network Service account, I realized that now my service cannot access local files. That means the services running under Network service can only access network resources but not local resources. I am not sure what's the motivation behind it though.

Next I tried creating a user defined account with the permission to access files both locally and remotely. I made my service to run under this new account. But still the service is not able to access network resources.

If I convert the service to a standalone EXE and run it, it is able to access network resources.

I have two more solutions to try. One of which is to update the windows service to impersonate another user through the code. Another solution is to map the driver within the service before accessing such drives. I am not sure how this might work out, I will keep you guys posted.

If you have a solution, your input will be much appreciated.