Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 使用批处理文件命名驱动器_Batch File - Fatal编程技术网

Batch file 使用批处理文件命名驱动器

Batch file 使用批处理文件命名驱动器,batch-file,Batch File,我正在寻找一个命令来重命名我在WinXP中每次启动时映射的几个驱动器。我已经搞定了映射部分,现在我对使用自定义名称以编程方式命名它们感兴趣,这样我就可以保持它们的简洁性了。在命令提示下,输入: LABEL x: yourlabel 其中,x:是您的驱动器号,yourlabel是您想要的名称 从标签/?: Creates, changes, or deletes the volume label of a disk. LABEL [drive:][label] LABEL [/MP] [vol

我正在寻找一个命令来重命名我在WinXP中每次启动时映射的几个驱动器。我已经搞定了映射部分,现在我对使用自定义名称以编程方式命名它们感兴趣,这样我就可以保持它们的简洁性了。

在命令提示下,输入:

LABEL x: yourlabel
其中,
x:
是您的驱动器号,
yourlabel
是您想要的名称

标签/?

Creates, changes, or deletes the volume label of a disk.

LABEL [drive:][label]
LABEL [/MP] [volume] [label]

  drive:          Specifies the drive letter of a drive.
  label           Specifies the label of the volume.
  /MP             Specifies that the volume should be treated as a
                  mount point or volume name.
  volume          Specifies the drive letter (followed by a colon),
                  mount point, or volume name.  If volume name is specified,
                  the /MP flag is unnecessary.

编辑:
正如@mark指出的,这不适用于映射驱动器。这似乎是一个常见的问题,可能有一种方法可以通过实现这一点,或者更简单一些,使用一个小的。

我放弃了DOS,转而学习了PowerShell。最终结果如下:

$Net = New-Object -ComObject WScript.Network  
$Rename = New-Object -ComObject Shell.Application  

#### # Map the local drives  
Subst Q: 'C:\File Path\Uno'    
Subst U: 'C:\File Path\Dos' 

#### # Map the network drives  
$Net.MapNetworkDrive("X:", '\\Server\File Path\Uno')  
$Net.MapNetworkDrive("Y:", '\\Different Server\File Path\Dos')

#### # Rename everything  
$rename.NameSpace("Q:\").Self.Name = 'Network -> FOO'  
$rename.NameSpace("U:\").Self.Name = 'Network -> BAR'  
$rename.NameSpace("X:\").Self.Name = 'Local -> FOO'  
$rename.NameSpace("Y:\").Self.Name = 'Local -> BAR'

实际上,不能在映射驱动器上使用标签。我不确定有没有解决办法,你说得对。看起来注册表或类似vbs的东西需要填补空白…vbs完成了以下任务:
mDrive=“q:\”
设置oShell=CreateObject(“Shell.Application”)
oShell.NameSpace(mDrive).Self.Name=“AnyName”

因为我无法在注释中输入新行)您心目中的“自定义名称”是什么?也就是说,您将如何使用这个名称?
 REM  ad label to any drive
 set SETl=TEMP
 set SETD=B
 echo strComputer = "." > LTEMP.vbs && echo Set objWMIService = GetObject("winmgmts:" _ >> LTEMP.vbs && echo     + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2") >> LTEMP.vbs && echo.  >> LTEMP.vbs && echo Set colDrives = objWMIService.ExecQuery _ >> LTEMP.vbs && echo     ("Select * from Win32_LogicalDisk where DeviceID = '%SETD%:'") >> LTEMP.vbs && echo.  >> LTEMP.vbs && echo For Each objDrive in colDrives >> LTEMP.vbs && echo     objDrive.VolumeName = "%SETl%" >> LTEMP.vbs && echo     objDrive.Put_ >> LTEMP.vbs && echo Next >> LTEMP.vbs && cscript LTEMP.vbs && del LTEMP.vbs