Naming network drives from commandline rather than Windows Explorer

让人想犯罪 __ 提交于 2020-02-24 20:55:10

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/21024844/naming-network-drives-from-commandline-rather-than-windows-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!