Поделиться через


Mapped Drive - Can't create Mapped Drive / Can't access Mapped Drive. What's happenning?

Developing with mapped drives on Windows machines, you can often get the similar messages like subject of this article. What’s wrong?

Even sometimes, you can see the mapped drive in explorer or using “net use”, but still your application can’t use it. Why?

 

The information has been documented on many KBs on https://support.microsoft.com like link below, but I am just trying to convey the message in different words.

INFO: Services and Redirected Drives

 

Reason: The information can be found documented at many places, I just want to point on the documentation of the API which is used to create mapped drive programmatically, WNetAddConnection2 Function (Windows), see Remarks Section.

Remarks

On Windows Server 2003 and Windows XP, the WNet functions create and delete network drive letters in the MS-DOS device namespace associated with a logon session because MS-DOS devices are identified by AuthenticationID (a locally unique identifier, or LUID, associated with a logon session.) This can affect applications that call one of the WNet functions to create a network drive letter under one user logon, but query for existing network drive letters under a different user logon. An example of this situation could be when a user's second logon is created within a logon session, for example, by calling the CreateProcessAsUser function, and the second logon runs an application that calls the GetLogicalDrives function. The call to the GetLogicalDrives function does not return network drive letters created by WNet function calls under the first logon. Note that in the preceding example the first logon session still exists, and the example could apply to any logon session, including a Terminal Services session. For more information, see Defining an MS-DOS Device Name.

So, if you create the mapped drive through explorer under user’s context and try to use it through a web application running under NETWORK SERVICE, the application code will fail to use mapped drive.

 

You can test it non-programmatically as well. I used Windows Vista for this demo.

 

1. Launch a command prompt as logged on user. Type below command.

Net use k: \\machinename\share

                If it is successful, the mapped drive will be created.

 

2. Launch a command prompt as “runas /user:someuser2 cmd.exe” by giving the password for “someuser2” . Type below command.

Net use

                You will see that the drive is not available, but in explorer windows you can see it.

 

3. Now from the command prompt launched in #2, run below command.

Net use k: \\machinename2\share

If it is successful, the mapped drive will be created.

 

Two mapped drives with same drive letter, with different target, on same machine…..?

 

4. Now you have two mapped drive created on the same system with same drive letter but to two different locations. How do you test it?

You can see the mapped drive created in #1 through explorer. Switch user to “someuser2” and see if there is another mapped drive created, which you created in #3.

 

Observe the difference. Mapped drives are restricted to per user.

 

I think above information is good enough to explain that mapped drives are strictly restricted to user specific.

 

Nitin Dhawan

Windows SDK – Microsoft