Windows Service UnauthorizedAccessException

G

Greyhound

I have created a Windows Service with C# in VS2008. I created the file
processing code first in a Windows Forms application that reads a flat file
on a network share. I am able to access the directory on the network and
access the files from the Windows Forms application. When I create and
deploy the Windows Service on my PC, I get an 'UnauthorizedAccessException'
exception stating that access to the specified network path is denied. The
code is the same on both applications except for the code required to make
the service run as a service. Are there special permissions required to
access a file on a network share?
Thanks...
 
I

Ignacio Machin ( .NET/ C# MVP )

I have created a Windows Service with C# in VS2008.  I created the file
processing code first in a Windows Forms application that reads a flat file
on a network share.  I am able to access the directory on the network and
access the files from the Windows Forms application.  When I create and
deploy the Windows Service on my PC, I get an 'UnauthorizedAccessException'
exception stating that access to the specified network path is denied.  The
code is the same on both applications except for the code required to make
the service run as a service.  Are there special permissions required to
access a file on a network share?
Thanks...

under what user your process runs?
how are you accessing the network share? Remember that you will not
have mapped drives so you have to access them by using its UNC: \
\servername\Share\
 
G

Greyhound

Thanks. My drive is using its UNC. As for the user the process is running
under, I am not sure how to answer. I run the Windows Forms app under my
logon. Do I need to do something different for the Windows Service on my
machine?
 
G

Greyhound

Ignacio,
If I do not do anything but create the Windows Service, deploy it, and start
it on my development machine, what user process is it running on?
Robert
 
W

Willy Denoyette [MVP]

Greyhound said:
Ignacio,
If I do not do anything but create the Windows Service, deploy it, and
start
it on my development machine, what user process is it running on?
Robert


Windows services per default, do not run in an account with network
credentials, so, if you want to access a share using it's UNC path, you'll
have to run the Service in the login account or in a domain account.
Search MSDN for System.ServiceProcess.ServiceProcessInstaller.Account for
detail on how to set the Service account.

Willy.
 
G

Greyhound

Thanks. That will sovlve my issue. Of the choices available to set, which
should be used to incorporate best practices, NetworkService or User?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top