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
- Summary
♦
The Story behind rename Network Drive VBScript
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.
VBScript to Rename a Mapped Network Drive
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.
Instructions
- 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.
‘ NameDrive.vbs
‘ VBScript to map a network drive.
‘ Authors Guy Thomas and Barry Maybury
‘ Version 1.4 – April 2010
‘ —————————————-‘
‘
Option Explicit
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
WScript.Quit
‘ End of Example VBScript.
Learning Points
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:"
Guy Recommends: The Free Config Generator
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!
Download your free copy of Config Generator
Problem with this neat Renaming VBScript
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"
Edit MountPoints, LabelFromReg with Regedit
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".
Summary – Renaming a mapped network drive
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.
Download my Logon Script eBook for only $6.25
The 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.
See more printer logon scripts examples
• Logon Script Home • Printer computer • Remove printer logon script
• AddWindowsPrinterConnection script • Multiple printers • Assign Logon Script AD
• EnumPrinterConnections • SetDefaultPrinter script • Free Import CSV Tool