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
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.
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 2005 ' ----------------------------------------' ' 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 strDiveLetter = "W:\" rather than "W:"
Guy Recommends: SolarWinds LANSurveyor
LANSurveyor will produce a neat diagram of your network topology. But that's
just the start;
LANSurveyor 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 take a free trial of LANSurveyor then you will
find a device on your network that you had forgotten about, or someone else
installed without you realizing!
Download a Free Trial of LANSurveyor
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.
See Also● Logon Script Home ●
MapNetworkDrive ● 5 Arguments of MapNetworkDrive |