Share via

Manual command for batch file to map network drive?

Anonymous
2010-06-06T12:24:50+00:00

Yesterday I worked with the network people at work in order to map all the network drives that I need after connecting through the VPN they provided.  After many tries (which involved making sure my domain name preceded my username) we finally got all my drives mapped.  Success.

However - I only use the VPN (and therefore need the mapped drives) occasionally.  I would like a way of "saving" the mappings (there are six of them, so it is no simple feat to redo them each time).  I know that I can "reconnect on login" after mapping them, but then every day when I boot up normally I get an error message that all my drives could not connect because they can only be accessed after I launch the VPN. 

Is there any way to write a batch file or create a script of have some way of easily mapping all six drives after I launch the VPN?  Back in the Netware days I used to write batch files to map drives all the time, but the map command doesn't seem to be available on Windows 7 64 bit Ultimate (which is the new system I just purchased).

Anyone have any ideas?  Thanks so much.

Regards

CJ Rhoads

Windows for home | Previous Windows versions | Internet and connectivity

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. Anonymous
    2010-06-06T13:23:39+00:00

    Windows 7 is able to process all the commands from the previous versions of Windows, plus a few extra ones. Here is the VPN batch file I use all the time. Save it as c:\Tools\MyVPN.bat, then create two new Desktop shortcuts:

    • Shortcut 1: c:\Tools\MyVPN.bat (to establish the VPN)
    • Shortcut 2: c:\Tools\MyVPN.bat xxx (to kill the VPN)

    @echo off

    goto Start


    Establish a VPN with xxx

    Parameters: RDP   - Start a Remote Desktop session

                other - Disconnect an existing session

    14.5.2010 FNL


    :Start

    net use /persistent:no

    if not "%1"=="" (

       net use * /d /y

       rasdial /disconnect

       echo Done!

       ping localhost -n 2 > nul

       goto :eof

    )

    set User=CRhoads

    echo.

    echo Creating a VPN under user %User%

    rasdial VPNName %User% * /domain:xxx

       /phonebook:"%UserProfile%\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk"

    if %ErrorLevel% EQU 0 (

      net use K: \192.168.1.11\Data

      net use L: \192.168.1.11\UserFiles

      net use M: \192.168.1.11\HR

      etc.

    )

    echo Done!

    ping localhost -n 5 > nul

    Note that the line above starting with the word "rasdial" is a very long line that ends with ".pbk". If it is broken up on your screen then you must rejoin it. Note also that you can remove the line "net use /persistent:no" after running the batch file for the first time.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful