Can a mapped network drive be reconnected from the command line?

On a daily basis I find myself in the Windows command prompt needing to access a network drive that is mapped but disconnected. I have yet to find a command that will reconnect this drive without unmapping and remapping (which leads to a password guessing game, since I don't own these computers). I would also like to be able to script this so every night the drive is reconnected if it has become disconnected somehow.

The fastest solution I currently have is to:

  1. Type "start." to open explorer,
  2. Alt-D to focus the address bar,
  3. type the drive letter I want and press enter, and wait for it to display the drive contents,
  4. then finally, close explorer and go back to the command prompt.

I know it's a minor inconvenience, but I'm often doing this through a slow VNC or PCAnywhere connection where doing anything through GUI is awful, so I'm just wondering if there's a better solution.


Maybe try pushd \\server\share?


I have to start Windows 7 before I can run the VPN program which connects me to the company network drives. Therefore my network drives don't automatically reconnect, only opening them in Windows Explorer reconnects them.

I have made a small batch file to start the VPN, reconnect the network drives, and start some applications I always uses.

In my Batch file I have the following:

REM Connect VPN here...

REM Opens an Explorer window looking at T: forcing a reconnect
Start /min explorer t:\

timeout 3 /nobreak

REM Kill all Explorer windows beginning with "T_drive" in the title
Taskkill /fi "windowtitle eq T_drive*"

REM Finish starting up here...

exit

The Taskkill /fi "windowtitle eq" command is case sensitive!


create a batch file (refreshletters.cmd) with these commands in it

(these will only work inside a batch file)

Tested on on Win7 and XP to refresh 'Disconnected' and 'Unavailable' driver letters in a console window (command line).

@echo off
net use |FIND ":" > %temp%\used.txt
FOR /F " tokens=1,2,3 delims= " %%i in (%temp%\used.txt) do (

  if %%i EQU Unavailable  (
    net use %%j %%k
    echo Activated %%j
   ) ELSE (
     if %%i EQU Disconnected (
       pushd .
       cd /d %%j
       dir . %>nul
       if NOT exist %%j\. (
          net use %%j /del /y
          net use %%j %%k
          echo Remapped %%j
          ) else (
             echo Fixed-up %%j
            )
       popd
       ) ELSE (
          echo Checked %%j
          )
     )
 )

This is probably a stupid question, but assuming your "disconnected" drive is H:, have you tried just changing directly to the drive?

It works for me under XPSP3:

C:\>net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
Disconnected H:        \\xxxxxx\wfaulk           Microsoft Windows Network
OK                     \\xxxxxxx\business        Microsoft Windows Network
The command completed successfully.


C:\>h:

H:\>net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK           H:        \\xxxxxx\wfaulk           Microsoft Windows Network
OK                     \\xxxxxxx\business        Microsoft Windows Network
The command completed successfully.

I know you said "net use" didnt work for you - but here is what you could try.

Run a batch file with net use /DELETE option to remove the existing/persistent connections And then you could use net use with the /SAVECRED option to re-use the passowd credentials used int eh last succesful logon. I am not sure if this will address your problem but its worth looking into.