Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an application that uses files on a network drive (K:) that normally is connected during user logon via net use K: \myserver\myshare .... The same files should be accessed by a windows service installed on a server. But the service doesn't fire a logon script, obviously.
It seems to me that all the mapped network drive stuff is available to an windows session (terminal server or client) and not to services which by definition run without the need of a user to be logged into the system. If so, what are my options?

share|improve this question

If the service is running as Local System or Network Service, or as a specific domain user, it can either access the files via the UNC path or it can map a network drive using the WNetAddConnection function. In the case of Local System or Network Service, the connection is made in the context of the Active Directory computer object.

If the service is running as a local user, UNC paths will not work, but it can still map a network drive using WNetAddConnection provided it can provide a valid username and password.

(If the Win32 API is not available for some reason, running the net use command in a subprocess will also work.)

share|improve this answer
very interesting answer. unfortunately, the server is part of a domain, while the machine that hosts the share is in workrgroup (it is in a dmz, so pulling the domain there is cumbersome). since i'm not the author of the service, i don't know where to put a WNetAddConnection call. I wonder if I can "script" a net use somewhere, but where is, in the service configuration, the entry point for scripting? – AgostinoX May 21 '12 at 12:54
I don't believe there is any supported way to do that. The service has to do it itself. There are some things that might work, that you could try, though. What account is the service running under? – Harry Johnston May 21 '12 at 21:56

Access the required files via their UNC path.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.