Error   test

Automated Mapping of Network Drives

Posted October 19, 2006 at 08:10pm in Computers, Programming

The other day I needed to make changes to my mapped drives and it seemed to be a pain more than anything. So I wrote this little script to map the drives on boot. The first portion of the code shows how to map drive. Each line is composed of the MapNetworkDrive command and parameters:

object.MapNetworkDrive LocalDevice, RemoteDevice [,SaveConnection] [,Username] [,Password]

I felt that it would be best to not register the share with windows and make it remap the drives at boot.

Option Explicit
On Error Resume Next
Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")

objNetwork.MapNetworkDrive "U:","\\SERVER\C", false,"USER","PASS"
objNetwork.MapNetworkDrive "V:","\\SERVER\D", false,"USER","PASS"
objNetwork.MapNetworkDrive "W:","\\SERVER\E", false,"USER","PASS"
objNetwork.MapNetworkDrive "X:","\\SERVER\F", false,"USER","PASS"
objNetwork.MapNetworkDrive "Y:","\\SERVER\G", false,"USER","PASS"
objNetwork.MapNetworkDrive "Z:","\\SERVER\H", false,"USER","PASS"

Wscript.Quit

This code should be saved to a seperate file for quick unmapping of network shares

Option Explicit
On Error Resume Next
Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")

objNetwork.RemoveNetworkDrive "U:"
objNetwork.RemoveNetworkDrive "V:"
objNetwork.RemoveNetworkDrive "W:"
objNetwork.RemoveNetworkDrive "X:"
objNetwork.RemoveNetworkDrive "Y:"
objNetwork.RemoveNetworkDrive "Z:"

Wscript.Quit

When I added this to startup I used my custom MMC panel and went to the Local Computer Policy \ User Configuration \ Windows Settings \ Scripts (Logon/Logoff) \ and added the location of the vbs script under the Logon scripts. I don’t feel I need to go into a deep explaination about any of this, but if you have questions feel free to contact me.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Google
  • del.icio.us
  • Digg
  • e-mail
  • Spurl
  • Facebook


Leave a Reply