8

I have a network drive already mapped. But I want to create a batch file that starts after the startup is complete and reconnect to the mapped network drives.

So far I have seen commands like:

net use Z: \\myserver\folder_name

But I think it maps a network drive. However I have already created a mapped network drive before. I want to connect to it.

Why I am not using reconnect at logon:

I have to connect to a VPN manually. Only after that will I be able to connect to the mapped network drive manually. Hence I am writing a batch file which connects to the mapped network drive, among other things like starting a few essential programs.

System Information:

Windows 7 Enterprise

Added Note:

In the link mentioned above "Can a mapped network drive be reconnected from the command line?" I see a somewhat working solution by Claus Melander. However the part where I am supposed to assign a title to the opened Windows Explorer window does not work. Because the opened window does not have the title I have specified.

REM Reconnect to mapped network drives
REM Y drive
REM Opens an Explorer window looking at Y: forcing a reconnect
start "Y_DRIVE" /MIN explorer Y:\
REM Wait for 5 seconds to allow it to reconnect, Ignore key presses and wait specified time during this time.
TIMEOUT /T 5 /NOBREAK
Taskkill /fi "windowtitle eq Y_DRIVE"

However, If I jump to a sub folder of the mapped drive, the statement to kill the application by filtering based on window title seems to work.

I am looking for a more elegant solution at this point.

Ayusman
  • 442

2 Answers2

11

If I understand you correctly, you need to programmatically disconnect the existing share before connecting, but are not sure whether it will be present or not.

net use z: /DELETE
net use z: \\myserver\folder_name

will unmap drive Z if it is already mapped, and then establish a network drive to the folder_name share.

Frank Thomas
  • 37,476
3

NET USE [driveletter:] \ComputerName\ShareName /PERSISTENT:YES That will always reconnect the drive on logon.

Erik
  • 264