VBScript Map Network Drives

This script will silently map specified network drives in the background and retry for a specified number of times with a specified delay before giving up. (Default: 10 retries per second for 120 retries)
You can change this by editing the script and changing:
delay = delay between each retry
timeout = number of retries

Using a batch command would also work but then you would see a black window popping up, hence the vb script.


In Windows 7 when you’ve mapped persistent network drives they can give error messages depending on different booting priority issues. This is a fairly common problem that doesn’t overall affect the functionality, it just adds an annoying pop up message on startup marking drives over with a red cross.

There are other workarounds that delay network before login or some such but that can cause other issues with services and this workaround was just simpler and quicker for me. This is just one example and with this simple script you can easily get rid of the message.

network drives error


If you already have mapped drives (persistent) you need to disconnect them.

1. First stepĀ  – Download the file or save the script manually

Right click this link and select save as / save link and download the script (mirror) directly.


Manually copy and paste the following text into your favorite plain text editor or windows notepad (not Microsoft Word) and save the file as MapNetworkDrives.vbs

'This script will silently attempt to map network drives of your chosing and retry doing so for 120 seconds
'If drive letters are already mapped the script will exit
set shell = wscript.createobject("WScript.shell")
set filesys = CreateObject("Scripting.FileSystemObject")

'Change this to the number of retries you want before giving up
timeout = 120
'Change this to the delay between retries, in milliseconds 1000=1 second
delay = 100

function MapDrive(pathNetwork, driveLetter,loginCred)
	count = 0
		if filesys.DriveExists(driveLetter) or count > timeout then 
			'msgbox "Drive exists"
			exit do
		end if
		commandString = shell.ExpandEnvironmentStrings("%WINDIR%") & "\system32\net.exe use " & driveLetter & ": " & pathNetwork & " /p:no " & loginCred
		'InputBox " "," ",commandString
		shell.run(commandString), 0, true
		WScript.Sleep delay
		count = count + 1
end function

'Copy and paste for each network drive to map
MapDrive "\\netgear\test1","Y","/USER:guest" 
MapDrive "\\netgear\test2","Z","/USER:guest" 
MapDrive "\\netgear\test3","W","/USER:guest" 

2. Second step – Edit the file

Edit the bottom of the file where it says MapDrive. Each line adds another network drive mapping so copy and paste for each drive you want mapped. Example:

MapDrive “\\netgear\test1“,”Y“,”/USER:guest

This example will map the folder test1 on a NAS server with the network name netgear with the drive letter Y.

3. Third step – Set it to start automatically when booting windows

If you’re on Windows 7 you can most probably just place it in your start menu startup folder.
Hold down the windows button and press R and type shell:startup and press enter to quickly open it.


On Windows 8 or more recent you can’t do that. Instead you must schedule a task to run on start up and login to launch the script. See instructions here.