Naming a Drive with a Batch File

I gave up on DOS and learned PowerShell instead. The end result worked like this:

$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'

From a command prompt, enter:

LABEL x: yourlabel

Where x: is your drive letter, and yourlabel the name you'd like it to have.

From LABEL /?:

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.

Edit: As @mark pointed out, this does not work with mapped drives. It seems this is a common problem, and there may be a way to achieve this via the registry, or somewhat easier, by using a small vbs script.

Tags:

Batch File