Reputation: 834
I have written a windows service which creates a file on local drive (C:\Testing folder).
I have installed this service. I am starting this service from web application hosted in IIS.
If i hardcode this path in service code, the service works fine but if I pass the path through web application to the web service, Events log showing an excepetion
Service cannot be started. System.UnauthorizedAccessException: Access to the path 'C:\Testing' is denied.
I have admin access on my machine and I am starting the service with the same account. How can I get rid of this exception?
Upvotes: 5
Views: 22875
Reputation: 167
When you map a drive on your local system then in such a case you are suppose to give rights to network service on shared folder you are accessing through windows service.
Upvotes: -1
Reputation: 834
I was making a silly mistake. I need to provide file name as well with the path. Its working fine now. Thanks for the responses
Upvotes: 6
Reputation: 11
You could try using something like Process Monitor to verify which account is trying to write to C:\Testing. It could be that an account other than the one you expect is trying to create the file.
Upvotes: 0
Reputation: 8582
As SpikeX said, your service needs to have read-write access to the folder c:\Testing
Right-click on the folder and change security permissions. "Local Service" for Local System account:
or if your service runs under a specific account (e.g. your own Windows admin account), give that account write permissions to the folder.
The service security tab in Services.msc:
Upvotes: 15