Home » Questions » Computers [ Ask a new question ]

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

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.

Asked by: Guest | Views: 73
Total answers/comments: 5
Guest [Entry]

Maybe try pushd \\server\share?
Guest [Entry]

"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
) ELSE (
echo Checked %%j
Guest [Entry]

"I have the same problem with multiple connections, and it's intermittent. When I reboot the computer, sometimes the connection is ""good"" and sometimes not. I don't have the password problem since I'm on a company LAN, but still I have the other aspect of the problem.

I've created a batch file called ex.bat, and stored it (along with many other things) in a \util directory that I put in my path. I can type ""ex h:"" and it will run Windows Explorer and set it to go directly to the h: drive. Here is the batch file:

start explorer /e,/select,%1

This works, with a lot fewer keystrokes. Or if it doesn't work at first, hit the Enter key to open the h: root folder and display the contents. Or, type ""ex h:\sub"" where the subfolder ""sub"" exists.

This problem seems to have gotten a lot worse recently, perhaps due to one of the Windows XP security patches.

Another thing to try is on the server side. On Windows servers, modifying a Registry key is supposed to keep the server from disconnecting its connections on a timeout. I do this on pretty much all our servers. The file is:

Windows Registry Editor Version 5.00

Guest [Entry]

"I had a similar problem and discovered I could force a reconnection with a simple ""dir x:"" from the command line (where X: was the mapped but disconnected drive.) This was from a Server 2003 system to mapped drives on XP and Win7 computers.

I created a batch file, wake_network_drives.bat, with these two lines:

dir x:
dir z:

and set a scheduled task to run it nightly before the backup program that was failing because the drives were occasionally showing as disconnected."
Guest [Entry]

"Just type:

NET USE H: \\server\share

(where H: is your drive letter of course)

Type 'NET /? USE' to see all options this command gives you."