简体   繁体   English

从命令行而不是 Windows 资源管理器命名网络驱动器

[英]Naming network drives from commandline rather than Windows Explorer

I'm writing a batch file to map multiple servers to drives on my PC.我正在编写一个批处理文件来将多个服务器映射到我 PC 上的驱动器。 Using the NET USE command, I have managed to map the drives successfully.使用 NET USE 命令,我成功地映射了驱动器。

When viewed in Windows Explorer, each drive shows the letter assignment and the server name.在 Windows 资源管理器中查看时,每个驱动器都会显示字母分配和服务器名称。 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?有什么方法可以从命令提示符(因此从批处理文件)而不是在资源管理器中右键单击和重命名为驱动器分配名称?

You can do it in Powershell like this:您可以在 Powershell 中这样做:

$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.只需将 X 替换为要在其上设置标签的驱动器号。

Alternatively if you don´t want to use Powershell you can do the following:或者,如果您不想使用 Powershell,您可以执行以下操作:

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当然,您必须将计算机名替换为服务器名,将共享名替换为共享名称,将 Drivelabel 替换为您的标签

The "label" value for a mapped network drive is stored in the registry.映射网络驱动器的“标签”值存储在注册表中。

Look into HKEY_USERS\\*SID*\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\MountPoints2.查看 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:).如果有一个名为 _LabelFromReg 的值,则您有一个自定义标签,如果该值不存在,则它使用默认标签,例如 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.您还应该能够使用组策略首选项以及网络文件夹和快捷方式来获取所需的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM