Mapping Network Drives at Multiple Locations

Background

Network drives allow multiple users on the same network to have acccess to the shared folders/files. However, if you have two different sets of network drives (at work and at home, for example), it can be a hassle to manually map drives when your computer 'resumes' on the new network.

For example, if I'm at work, all my network drives are available. When I go home and connect to the local network, my work network drives disappear (that's fine, they're not available anyway) but my home network drives don't automatically map. The same is true when going from 'home' back to 'work'.

Manually mapping a network drive isn't difficult, but if you have to map multiple drives, multiple times a day, it's a hassle.

Solution

To make mapping easier, I designed a vbscript file that can map any number of network drives. The script file accepts one parameter at the command line - the name of the text (.txt) file containing the drive mappings you want.

With this in place, I can execute the command MapNetworkDrives.vbs drives-work.txt or MapNetworkDrives.vbs drives-home.txt to re-map my home or work drives, respectively. These commands can be easily saved as a shortcut (double-click the shortcut to map your drives) or built into an AutoHotKey script to detect your network and intelligently choose which drives to map.

Getting Started

To make this work, you need at least two files.

MapNetworkDrives.vbs is the script file that does the processing and mapping.

drives-work-sample.txt is an example of a file containing mappings. This file can be named anything you prefer; what's important is the format and contents of the file. The following note (also available inside MapNetworkDrives.vbs) explains that format:

This script maps network drives, based on an argument passed at the command line
The text file passed as argument 0 needs to be plain text, with a drive to map on
each line. The lines need to be pipe-separated (|), in the format:
DriveLetter | UNC Path to map | Name to be assigned to mapping
Optionally, a username and password can be provided to the script for each mapping:
DriveLetter | UNC Path to map | Name to be assigned to mapping | username | password

You'll want a separate version of this file for each network location at which you want to map drives.

To get the code, and read how to set up a Windows Desktop Shortcut to automate mapping your drives, click through for page two.

Setting up a Shortcut

  • On you Windows desktop, right-click, then click New->Shortcut.
  • Click Browse..., then navigate to the location where you stored MapNetworkDrives.vbs, click on that file, then click Ok, and then click Next.
  • Type a name you like for the shortcut, or accept what's there with the Finish button.
  • Right-click your new shortcut, and click Properties
  • In the Target field, you should see the full path to your MapNetworkDrives.vbs file. You need to add a space, and then the name of your mappings file (drives-work-sample.txt) to the Target. For example:

    C:\Users\john\Documents\MapNetworkDrives.vbs drives-work-sample.txt

  • Click Ok once you've got the Target field completed.

You can now double-click the shortcut to map your drives. It should work, assuming the drives are available on your current network.

Full Code

Here are links to the full, working code for both files discussed.

You'll need to remove the "_.txt" file extension from the MapNetworkDrives.vbs_.txt file once you have it downloaded.

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.