Windows – how to easily reconnect to “unavailable” network shares

windowswindows-command-promptwindows-net-command

Every once in a while, I run cmd as my admin user.
I set up a shortcut for convenience sake…

C:\Windows\System32\runas.exe /u:admin.user@domain cmd 

At some point, I've wanted to run scripts that point at mapped drives available to my regular user.

C:\Windows\system32>net use
Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Unavailable  L:        \\fileserver\shared\path
                                                Microsoft Windows Network
Unavailable  X:        \\fileserver\shared\temp         Microsoft Windows Network
The command completed successfully.

I'm specifically interested in getting my L: drive to map. I think something like this should work…

C:\Windows\system32>net use l:
Local name        l:
Remote name       \\fileserver\shared\path
Resource type     Disk
The command completed successfully.

C:\Windows\system32>l:
The system cannot find the drive specified.

If I re-map the drive, everything is happy, but its a chore ("path" a lot longer in reality).

C:\Windows\system32>net use l: \\fileserver\shared\path
The command completed successfully.

C:\Windows\system32>l:

L:\>

Best Answer

Try this one:

for /f "TOKENS=3,4" %a in ('net use') do net use %a %b

C:\>n:
The System cannot find the drive specified

C:\>for /f "TOKENS=3,4" %a in ('net use') do net use %a %b
... [Ignore the output] ...

C:\>n:

N:\>