Map Network Drive – Windows Logon Scripts

Introduction to Map Network Drive Logon Scripts

This page is a mini sitemap specializing in VBScripts to map network drives.  In this section, I will show you how to build VBScripts for mapping home drives to network shares.  Each page has detailed examples of a different VBScript method, for instance, MapNetworkDrive, which connects a drive letter (H:) to a UNC path on a Windows server.

For more complicated scripts we need to employ several methods in the same script.  I will explain how to build scripts which enumerate network drives, then if necessary, remove drive mappings and finally map the drive letters to your specification.

Topics for Map Network Drive Windows Logon Scripts


Our Mission

Our mission is to create scripts, which provide access to Windows network resources.  Users and some applications, prefer to connect to a mapped network drive letter, than type the UNC path in the Run dialog box.  As with so many scripts, the map network drive logon scripts mimic actions that users could perform manually.  Explorer has all the tools to display, create and disconnect mapped drives.  However, if you code these same commands in a logon scripts and not only do you save time, but once perfected the code never makes a mistake.

Map Network Drive Methods

In common with other scripting languages, VBScript uses three components an object, a method, and a value.  Most of my scripts create objects using names beginning with obj, for example objNetwork.  What gives any scripting language power is the rich variety of methods or verbs.  Here is a list of examples of map network drive methods.

Also More windows Logon Script Ideas

Guy Recommends: SolarWinds Network Topology Mapper (NTM)SolarWinds Network Topology Mapper

NTM will produce a neat diagram of your network topology.  But that’s just the start;Network Topology Mapper can create an inventory of the hardware and software of your machines and network devices.  Other neat features include dynamic update for when you add new devices to your network.  I also love the ability to export the diagrams to Microsoft Visio.

Finally, Guy bets that if you test drive the Network Topology Mapper then you will find a device on your network that you had forgotten about, or someone else installed without you realizing!

Download your 14 day free trial ofSolarWinds Network Topology Mapper

Example – MapNetworkDrive

The purpose of this VBScript is to map the H: to a share called ‘\home’.  In my example the server is called ‘\\alan’.


  1. On Line 2 change the name of the server from ‘\\alan’ to the name of your server.  You need a computer with a network share.
  2. Make sure that the shared folder is called ‘\home’.  Alternatively, alter the word ‘\home’ in the script if your share is called something else.

Instructions to MapNetworkDrive

  1. Copy and paste the script below into notepad or get a script editor such as OnScript (free download).
  2. Change the server name from "\\alan to the name of your server.
  3. Check the share name ‘\home’.
  4. Save the file with a .vbs extension, e.g. MND.vbs or MapNetworkDrive.vbs.
  5. Double click the resulting script and look in your Windows Explorer for a new drive letter called : home on ‘alan’ (H:)

Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "H:" , "\\alan\home"

Learning Points

Note 1: If you run the script a second time, then you get WSH error message code 80070055.  The solution is launch Windows Explorer, just right-click on: home on ‘alan’ (H:) and select: Disconnect.

Note 2: I cut this script down to the bare minimum to map a network drive.  Here are more comprehensive examples of Map Network Drive

Recommended: Solarwinds’ Permissions Analyzer – Free Active Directory ToolFree Permissions Analyzer for Active Directory

I like thePermissions Analyzer because it enables me to see WHO has permissions to do WHAT at a glance.  When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, and takes into account network share access, then displays the results in a nifty desktop dashboard!

Think of all the frustration that this free SolarWinds utility saves when you are troubleshooting authorization problems for user’s access to a resource.  Give this permissions monitor a try – it’s free!

Download SolarWinds’ Free Permissions Analyser – Active Directory Tool

PowerShell and Logon Scripts

Both DOS and VBScript are being superseded by PowerShell, even for connecting to printers or mapping network drives.

Remember that PowerShell is designed for configuring the operating system rather than setting the user environment.  However, it’s possible for PowerShell to create a ComObject, which can act as a wrapper for VBScript commands. Here is example of PowerShell’s New-Object cmdlet manipulating a MapNetworkDrive method:

# PowerShell Logon Script Example
$PSnet = $(New-Object -ComObject WScript.Network)
$PSnet.MapNetworkDrive("H:", "\\BigServer\Stuff")

You can save these instructions in a .ps1 file.  However, the hard part is executing  this .ps1 file as a logon script.  See more about assigning a PowerShell logon script.

Map Network Drive Summary

All my scripts are copyright fee, go ahead an copy my scripts and amend them to your Windows network.  I do hope that will take the time to learn more about the NetworkDrive family of methods, for example, MapNetworkDrive, RemoveNetworkDrive, or  EnumNetworkDrives.


Download my Logon Script eBook for only $6.25

Logon ScriptThe extra features you get in your eBook include, more pages full of detailed examples.  Also, ten ‘how to…’ sections, with screen shots showing which menus to use.  Go for Guy’s eBook – and get a printable version with copy enabled and no expiry date.

  Jumbo Script 7 Package

If you like this page then please share it with your friends


See more logon scripts examples

Logon Script Home   •EnumNetworkDrives   • Map Network Drive Group   • Free Import CSV Tool

Map Network Drive Script   • Vbscript Map Network Drive Username   • Map Multiple Network Drives

ObjNetwork.MapNetworkDrive   • Disconnect Network Drives   • Logon script group policy