Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 751
Rohit Ramname Avatar asked Feb 07 '12 21:02

Rohit Ramname


People also ask

What is difference between Windows Service and worker?

Windows Services have existed for over 20 years. They start most often at system startup and run permanently. A Worker Service is also a real process, but is intended as a background service for a front-end application; it starts with the application and stops with the application.


1 Answers

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

like image 132
AFD Avatar answered Oct 07 '22 14:10

AFD