views:

214

answers:

5
+1  Q: 

windows service

Hi,

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

A: 

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

PhoneTech
The service is running using my local account. If I run the application using console mode then it writes in network mapped drive.
gopal
+4  A: 

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.

Michael Barth
+1  A: 

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.

Swinders
A: 

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.

Jonathan
I tried it. The service is running in NetworkService mode. But it is not able to write in network mapped drive.
gopal
I found an extended discussion about this issue: http://bytes.com/groups/net-c/234214-access-mapped-drive-windows-servicehope it helps.
Jonathan
Mapped drives won't work for a service. You need to use a UNC path instead.
tomfanning
A: 

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

jdehaan