Introduction to Map Network Drive – Rename Mapped Drive
After you create a new mapped network drive, if you look in Windows Explorer, then what you see under Network Drives is: ‘sharename on server (W:)’. I have discovered how to rename this display string by writing a VBScript. A word of warning, the side-effect of my script is that all mapped drives get the name specified by strNewName. However, I will show you a Regedit technique to correct this undesirable effect.
Topics for Rename Network Drive
- The Story behind Rename Network Drive VBScript
- VBScript to Rename a Mapped Network Drive
- Problem with this neat Renaming VBScript
- Edit MountPoints, LabelFromReg with Regedit
Here is the story behind this script. For ages, readers have been asking me how to control the name of a mapped network drive. At the back of my mind, I knew it must be possible to rename this drive letter namespace. My thinking was that if you can manually, right-click and rename the mapped drive, then it should be possible to do the same job with a VBScript.
Then one day, Barry kindly sent me a VBScript, which renamed the local drive letter. I simply love readers who send me script ideas. I thank you again Barry.
When you map a network drive, the operating system automatically calculates an appropriate name for the label that you see in Explorer. The formula that XP uses is: sharename & computer description name & (Letter). For example: Home on Green Server (z:).
Note Jesper Hoffmann Larsen found that you must have the backslash in the drive-string, e.g. z:\ worked for him, not my plain z: naming.
- Copy and paste the script below into notepad or get a script editor such as OnScript (free download).
- Save the file with .vbs extension e.g NameDrive.vbs
- Change the server \\ alan to a server on your network. Similarly make sure that you have a share called \home, else change the UNC path in the script.
- Double click and then open explorer and check the drive name.
‘ VBScript to map a network drive.
‘ Authors Guy Thomas and Barry Maybury
‘ Version 1.4 – April 2010
Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName
strDriveLetter = "W:"
strRemotePath = "\\alan\home"
strNewName = "Boss Reports"
‘ Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
‘ Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName
Wscript.Echo "Check : "& strDriveLetter & " for " & strNewName
‘ End of Example VBScript.
Note 1: Observe how we create a shell object in addition to the usual network object.
Note 2: The key command is: objShell.NameSpace(strDriveLetter).Self.Name. Let us breakdown this statement into three parts:
a) NameSpace(), means: ‘go and get the name of what ever is inside the brackets’, in our case strDriveLetter.
b) The next feature almost speaks for itself .Self.Name; meaning get the name attribute.
c) Finally we set the value of strDriveLetter = strNewName.
Note 3: I say again, if this does not work for you, try adding a backslash to the strDriveLetter = "W:\" rather than "W:"
SolarWinds’ Config Generator is a free tool, which puts you in charge of controlling changes to network routers and other SNMP devices. Boost your network performance by activating network device features you’ve already paid for.
Guy says that for newbies the biggest benefit of this free tool is that it will provide the impetus for you to learn more about configuring the SNMP service with its ‘Traps’ and ‘Communities’. Try Config Generator now – it’s free!
The problem is that once give the mapped network drive your name, strNewName, then it always gives that particular drive letter strNewName. Let me illustrate by way of an example.
V: is mapped to \\ alan\reports. You set strNewName = " Boss Reports".
Let us assume that later, you map the V: drive to \\ betty\tax. Unfortunately, the V: drive will still be called strNewName. The network share will appear to be "Boss Reports" (V:), not ‘Tax on Betty (V:)’.
Good news; there are two solutions. It has probably occurred to you that all you have to do is re-run the script, but change:
strNewName = "Boss Reports" to strNewName = "Tax on Betty"
Alternatively, you could edit the registry. What I did was launch regedit and then click on Edit (menu), Find, "Boss Reports". Much to my surprise, the value turned up under MountPoints. The full path was
HKCU, Software, Microsoft, Windows, CurrentVersion, Explorer, MountPoints2, then the Reg_SZ was called _LabelFromReg. My advice is to just delete the value – leave it blank. The result will be that future drive mapping will revert to the traditional style of mapping. ‘Tax on Betty".
Does the name that the operating assigns a mapped network drive annoy you? If so, then here is just the script to rename that long description, With a VBScript, you can persuade Explorer to display name that you chose for mapped Network Drive text.