Elevated command line prompt can't access shared drives

66

17

  1. I map a share from another machine using my user account.
  2. I launch an elevated command prompt (cmd.exe, right click, Run as administrator).
  3. Navigating to shared drive (Z:) results in:

The system cannot find the drive specified

Now if I open a non elevated command prompt, I can navigate to Z: just fine.

mindless.panda

Posted 2010-10-14T12:04:00.647

Reputation: 6 642

Answers

48

Opening a Windows Explorer as administrator and recreating the network shares didn't work for me. Then, I found this solution: create the share on the command prompt itself. It worked for me.

net use f: \\remoteserver\subfolder      

Even if the drive is already mapped in windows explorer, still it worked.

Note: Only use a single backslash before subfolder

msb

Posted 2010-10-14T12:04:00.647

Reputation: 1 167

25

Probably that is not a problem of file permissions but it's related with:

  • Network shares being associated with sessions (i.e. different users may have a different set of network shares). Note that an user can have more that one session.
  • How User Account Control works.

Since almost all users used an administrator account in XP (as most programmers didn't bother to make their programs work with limited accounts), Microsoft made a "limited version" of administrator accounts starting with Vista, an in some situations the two "versions" counts as different users (since they are separate sessions).

Try launching an elevated Windows Explorer (i.e. a Windows Explorer launched with "Run as administrator") and recreate all network shares, that should do the trick.

The reason for having to recreate the shares is explained on this MSDN blog entry:

Mapped Network Drives with UAC on Windows Vista

Edit: relevant bits from the blog entry (emphasis mine):

To simplify things, let's assume you are running as an administrator with UAC enabled (although, to be more secure, it is better to run as a standard user). When you log in, you create a new token. We then detect that you have UAC enabled, we log in a second time, and end up with a new (highly restricted) token, which we use to launch the shell. There are two separate login events.
(...)
This convenience feature makes it easier to run into issues with mapped network drives. Prior to Windows 2000 SP2, device names remained globally visible until explicitly removed or the system restarted. For security reasons, we modified this behavior beginning with Windows 2000 SP2. From this point forward, all devices are associated with an authentication ID (LUID) - an ID generated for each logon session.
(...)
Because these mapped drives are associated with LUID, and because elevated applications are using a different LUID generated during a separate login event, the elevated application will no longer see any mapped drives for this user.

Alberto Martinez

Posted 2010-10-14T12:04:00.647

Reputation: 1 235

1@mindless.panda : You are absolutely right. The "Run as administrator" option refers entirely to the UAC-related Administrator setting. It simply has nothing to do with the Administrators group. If you disable UAC (which may require a reboot to fully take effect), you may find the "Run as administrator" option doesn't even exist while UAC is disabled. Note that an Administrator command prompt can still use the shared drives as UNC, e.g. \servername\dirname --it's just the drive letters that get lost just because that's how Microsoft designed it. Remake 'em, and all's good in that prompt. – TOOGAM – 2015-02-03T20:29:56.993

I'm administrator, I can't launch an explorer window elevated (Win 8) – user15507 – 2017-04-03T16:52:26.243

4i used an elevated Windows Explorer, and the elevated Command prompt still cannot find the mapped drive. – icelava – 2011-12-27T03:04:45.873

1My understanding is that in Windows 7 when I "Run as administrator", its not actually running as the account with the name "Administrator" (Windows XP-ish), but rather as my account but with some super user bit set. I don't understand then why there is any difference between the two scenarios I described. – mindless.panda – 2012-03-06T16:15:48.227

1There is a difference because the two "versions" of any administrator accounts for some aspects works as different account, even if they are really the same account with different permissions (that is explained in the blog I linked). – Alberto Martinez – 2012-03-11T14:12:45.320

7

Alberto Martinez answer describes why the mapped network drive is not accessible.

Here is registry fix to solve the problem:

  • Open regedit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
  • Add a new DWORD (32-bit) Value named EnableLinkedConnections.
  • Adjust the value to 1 (or 00000001).

Exit regedit and restart the computer.

user1251007

Posted 2010-10-14T12:04:00.647

Reputation: 643

Ref: https://technet.microsoft.com/en-us/library/ee844140(v=ws.10).aspx

– UuDdLrLrSs – 2017-07-05T13:36:36.500

1This is definitely the best solution for this problem. – alecov – 2018-07-24T02:32:00.340

1Does not work on Win10 – Christian Schäfer – 2018-09-23T11:12:40.107

or windows server 2016 – R.M. – 2019-05-03T16:18:55.343

1

I map a share from another machine using my user account.

that network drive is available ONLY in user account mapped the network drive.

undone

Posted 2010-10-14T12:04:00.647

Reputation: 824

0

Start cmd as administrator, type in the command net use z: \\net\path /persistent:yes and you're done. Another thing I did, and this is extending past the op's question, was after pinning the cmd to the task bar and in properties->Advanced setting it to run as admin, I added /K z: to the end of the 'target' text box, so it became: %windir%\system32\cmd.exe /K z:. Because setting the "Start in" parameter didn't seem to work. This resulted in an icon on my taskbar that starts a cmd window as admin and with the prompt on the mapped drive. And don't forget to go to the properties again and customizing the font, colors, window size and position, as well as text scroll back buffer and command history buffer sizes!

Martin Hjerne

Posted 2010-10-14T12:04:00.647

Reputation: 1

-2

Verify your network path, and disconnect the mapped drive (Z:) Run CMD as administrator, once there, use the "net use" command to map the drive again. net use Z: \SharePath then try access it again.

AlexR

Posted 2010-10-14T12:04:00.647

Reputation: 1