0

The title says it all.

User maps a drive letter L: to the share \\server\share. User is then able to access L: from the command line, and any program started by User from the command line or Explorer is able to do the same.

Yet, a service running under the same User cannot see the drive letter L: at all. The same service program run from the command line, manually, instead can.

Obviously there are differences among the two cases, but I cannot find any documentation about it neither I can find a way to make the drive letter L: accessible to the service.

Any help?

1

1 Answer 1

2

Mapped drives are tied to the login session. The service would not be running in the “physical” session, even if it is running under the same user account.

If you want the service to have a mapped drive, the service has to map the drive itself. This is possible directly using the WNetAddConnection2 Win32 API or using tools like net.exe. Please also note that “persistent” mapped drives do not apply to non-interactive sessions.

I would recommend not using a mapped drive at all. Access the share directly instead.

2
  • Thanks, that clarifies things a lot. Do you have any pointer to the official documentation about this? Also, assuming the share was accessed directly, what would happen if it required credentials to be accessed? Would WNetAddConnection2 help in that case too, perhaps passing NULL as a LocalName?
    – Fabio A.
    Dec 21, 2022 at 13:38
  • 1
    According to the documentation, using WNetAddConnection2 like that should work. I haven’t test it though.
    – Daniel B
    Dec 21, 2022 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .