The Furious Bear
The Furious Bear

Reputation: 572

Naming network drives from commandline rather than Windows Explorer

I'm writing a batch file to map multiple servers to drives on my PC. Using the NET USE command, I have managed to map the drives successfully.

When viewed in Windows Explorer, each drive shows the letter assignment and the server name. I'd like to display a user-friendly plain-English name for each server in the Explorer view also (this is different from the volume label). I can right-click on each drive individually in Explorer and rename but this is a bit long-winded.

Is there any way that names can be assigned to the drives from the command prompt (and therefore from a batch file) rather than right-clicking and renaming in Explorer?

Upvotes: 5

Views: 11723

Answers (2)

tommymaynard
tommymaynard

Reputation: 2152

The "label" value for a mapped network drive is stored in the registry.

Look into HKEY_USERS\*SID*\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2. There should be a key that represents the mapped network drive. If there is a value called _LabelFromReg you have a custom label and if the value is not there then it uses the default label, such as, Windows (\server\share) (Z:).

You should also be able to use Group Policy Preference, and Network Folders and Shortcuts to get the labels you want.

Upvotes: 4

Paul
Paul

Reputation: 5871

You can do it in Powershell like this:

$rename = new-object -ComObject Shell.Application
$rename.NameSpace("X:\").Self.Name = "DriveLabel"

Just replace the X with the drive-letter on which you want to set the label.

Alternatively if you don´t want to use Powershell you can do the following:

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##computername#sharename" /f /v "_LabelFromReg" /t REG_SZ /d "DriveLabel"

Of course you have to replace computername with the servername, the sharename with the name of the share and the Drivelabel with your label

Upvotes: 8

Related Questions