On occasion, an administrator may need to change drive-mapping names to hide share paths or to make the drive name user-friendly. If done manually through a console, this is a simple-enough operation.
But try to automate the task and it gets more difficult. Because mapped drives are not partitions on the local hard disk, common DOS commands can't be used. Most drive-mapping commands, such as net use, don't have a way to customize the name of the mapped drive either.
One way to perform this task is to hack the following Registry key and add the _LabelFromReg string value:
Here, the %key% variable is the drive letter to be changed.
There are several ways to make this method work. You can edit the Registry directly, via script, or by importing a .reg file using regedit/c. But all these methods require many steps and some require external files, and so they might not fit into every administrative scheme. Here's an easier approach.
Using a VBScript can make this task more seamless. This simple script can be used on mapped drives as well as local partitions:
mDrive = "drive letter" Set oShell = CreateObject("Shell.Application") oShell.NameSpace(mDrive).Self.Name = "AnyName"
To use this trick, simply edit the script to change the drive letter and drive name as desired. For example, if Z: is a mapped drive that
mDrive = "drive letter"
mDrive = "z:\" Then, change this line:
oShell.NameSpace(mDrive).Self.Name = "AnyName"
oShell.NameSpace(mDrive).Self.Name = "Backup"
Finally, run the script by creating a shortcut to it and double-clicking on the shortcut, either by calling it from a logon script or by any other method suitable for your environment.
About the author: Rahul Shah currently works at a software firm in India, where he is a systems administrator maintaining Windows servers. He has also worked for various software firms in testing and analytics, and also has experiences deploying client/server applications in different Windows configurations.
More information on this topic:
- Tip: Script
retrieves remote drive mappings and printers
- Topics: Windows
- RSS: Sign up for our RSS feed to receive expert advice every day.
This was first published in August 2006