Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming a Drive with a Batch File

Tags:

batch-file

I am looking for a command to rename a few drives that I map every start-up in WinXP. I've got the mapping part down, I'm now interested in naming them programmatically with custom names, so I can keep them straight.

like image 363
codo-sapien Avatar asked Sep 26 '12 19:09

codo-sapien


1 Answers

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'
like image 189
codo-sapien Avatar answered Nov 15 '22 09:11

codo-sapien