Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

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

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 Info:

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 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 app by filtering based on window title seems to work.

Looking for more elegant solution ath this point.

share|improve this question
    
sounds a little different from the linked question (which is about resuming a disconnected network drive) which is one of the possible states the op could be dealing with, but another is the case where the connection does not exist at all yet still needs to be handled. –  Frank Thomas May 13 '13 at 16:01
1  
This is NOT a duplicate question. My problem is entirely different. –  Ayusman May 13 '13 at 21:21
add comment

marked as duplicate by MaQleod, techie007, Brad Patton, Mokubai, terdon May 14 '13 at 0:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

If i understand you correctly, you need to programatically 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 z if it is already mapped, and then establish a network drive to the folder_name share.

share|improve this answer
    
I do not want to disconnect the existing share. Because it's not connected to begin with. Just as I do it in a windows explorer window; I just double click on the window and it comes up. The solution you are trying to suggest is to remove the mapping and remap it. My point is since the mapping is already provided in the past, I should not have to re-map it, I just have to reconnect it. –  Ayusman May 13 '13 at 21:01
    
@Ayusman It just doesn't work that way. A "disconnected" drive (with the red cross through it) isn't really connected AT ALL. Explorer just remembers it from a previous session and will (behind your) back call "net use" when you double-click it. To do it in a batch file you have to call "net use" yourself. That is the only way to do it. –  Tonny May 13 '13 at 21:32
    
@Tony ok, I took your advise. I will have to restart my PC and see how it works. Thanks for the input. –  Ayusman May 13 '13 at 21:51
add comment

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

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.