Creating a file using the Windows service

I wrote a Windows service that creates a file on a local drive (folder C: \ Testing).

I installed this service. I am starting this service from a web application hosted in IIS.

If I hard-coded this path in the service code, the service works fine, but if I go through the web application to the web service, an event log showing excepetion

The service cannot be started. System.UnauthorizedAccessException: Access to path "C: \ Testing" is denied.

I have administrator access to my machine, and I'm starting the service with the same account. How can I get rid of this exception?

+4
source share
4 answers

I made a stupid mistake. I need to specify the file name as well as the path. Now it works fine. thanks for answers

+4
source

As SpikeX said, your service should have read and write access to the c: \ Testing folder

Right-click the folder and change permissions. "Local service" for the local system account:

enter image description here

or if your service runs under a specific account (for example, your own Windows administrator account), give permission to write the account to this folder.

Security tab in Services.msc:

enter image description here

+12
source

You can try using something like Process Monitor to check which account is trying to write to C: \ Testing. It is possible that another account is trying to create a file.

0
source

When you map the drive to the local system, then in this case you must grant the rights to the network service in the shared folder that you access through the Windows service.

-one
source

Source: https://habr.com/ru/post/1395313/


All Articles