gopal
gopal

Reputation: 3741

windows service

I developed a windows service to write PDF file in a directory. The service has no problem writing files to local drives. But when it tries to write to network mapped drives, it fails and writes the file in the application directory.

Upvotes: 3

Views: 1097

Answers (5)

jdehaan
jdehaan

Reputation: 19938

I would check following:

  1. Does your program work when not running as a service?
  2. Are you sure not having any GUI elements like error boxes (stupid question maybe ;-) )?
  3. Are you writing a service using .NET? if yes there are maybe issues with dynamic rights (CAS)

Perhaps you have problems debugging the service: you can attach the debugger on it and then tell us which error you are getting. That will help the people here to help you.

CAS

Upvotes: 0

Michael Klement
Michael Klement

Reputation: 3414

Here are some experiences I had while creating the same service as you did (reading and saving PDF on a network drive). I had 2 drives: The first without the need of authentication and the second where you had to authenticate.

Common faults with mapped network drives

  • UNC Path vs Drive Letter: Drive letter's don't work, you have to specify your path using the UNC notation. (e.g. \\10.17.194.1\RemoteDir\)

  • Authentication: If the network drive needs you to authenticate, the only way I found was to create the authentication user on the machine running the service. If you need to authenticate as "RemoteUser" with "RemotePassword" to access the network drive, you should create a RemoteUser/RemotePassword account on the server and let the service run as this user.

    If you don't have the rights to access the directory you'll be getting a exception telling you it could not find the directory/file or rather that it does not exist.

  • Service can't establish connection by itself: Also, it is mandatory to access the network drive at least once manually from the explorer so you can browse it. My service was unable to establish a connection to the network drive by itself, it had to be established in the explorer before.

I hope any of this points help you.

Upvotes: 5

Jonathan
Jonathan

Reputation: 12025

I think that by default a windows service runs under the LocalService account so Services do not get any special priviledges by default. Maybe if you change the account of the service to the NetworkService account it will work.

Upvotes: 0

Swinders
Swinders

Reputation: 2281

You need to make sure the account type the service is running as can access the network.

The 'Local System' user will probably not have permission to access the network mapped drive but could write to the local hard drive. You should be able to set the user the service is run as to one that has network share permissions.

Upvotes: 2

bartv
bartv

Reputation: 197

Have you tried setting the write permission on the network drive to accept the user running the service?

Upvotes: 0

Related Questions