Rohit Ramname
Rohit Ramname

Reputation: 834

Creating file using windows service

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

Answers (4)

saransh mehra
saransh mehra

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

Rohit Ramname
Rohit Ramname

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

MarkF
MarkF

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

Andrei Drynov
Andrei Drynov

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:

enter image description here

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:

enter image description here

Upvotes: 15

Related Questions