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?
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.)Access the required files via their UNC path.