1

I map a network drive via command line. Once this drive is mapped, it appears under My Computer with the full path.

How can I rename the mapped drive using command prompt?

I have used the "full path name of the folder" & "new name of the folder" command, which works perfectly but when I use it to rename the drive, it does not work.

3
  • Do you mean, change the drive letter?
    – dsolimano
    Commented Nov 7, 2013 at 14:15
  • Nope. I mean the label of the drive letter. The name itself. Not the letter. Like this, Client (\\192.168.1.100) (z:) .... I want to rename it with only Client will show and the drive letter...
    – user
    Commented Nov 7, 2013 at 14:20
  • Renaming it and removing the ip address MANUALLY will totally work. But I want to apply it using the comman prompt because I will further code it using JAVA. Any suggestions?
    – user
    Commented Nov 7, 2013 at 14:23

2 Answers 2

2

There seem to be two approaches, both listed in this question/answer at ServerFault. I much prefer the VBScript approach, which is also described here.

Set oShell = CreateObject("Shell.Application")
oShell.NameSpace("H:\").Self.Name = "your_label"

So I would create a small VBScript script, which takes the drive letter as one parameter, and the new label as the second. My VBScript is rusty, but according to this Stack Overflow question, something like this:

Set oShell = CreateObject("Shell.Application")
oShell.NameSpace(WScript.Arguments.Item(0)).Self.Name = WScript.Arguments.Item(1)

If you call that rename_drive.vbs, you can execute it as

wscript rename_drive.vbs H:\ new_drive_name

Of course, if you're comfortable creating COM objects from Java, you can do that directly.

1
  • +1 because the answer seems useful. (Not that I have taken the time to test it.) History shows Community bumped this question, which led to me giving it a bit of attention, and deemed the effort worthwhile. Good job, thanks. You could also use cscript instead of wscript. (Since there are no message boxes, presumably the normal result is that this would just successfully accomplish the task identically regardless of which command was used.)
    – TOOGAM
    Commented Jun 2, 2016 at 7:45
0

Based on the VBScript approach, you can also perform the same operation using PowerShell.

function Set-DriveName($Drive, $Name){
    (New-Object -ComObject Shell.Application).NameSpace($Drive).Self.Name = $Name
}

And then use the function

Set-DriveName -Drive "Y:" -Name "Drive Name"

Alternatively, if you want to launch this from CMD or from another application, you can use this command:

powershell -c "(New-Object -ComObject Shell.Application).NameSpace('Y:').Self.Name = 'Drive Name'"

PLEASE NOTE: Do not run this command as Administrator if you're trying to rename mapped drives visible only to the local user. You need to run this command in the context of the target user where the target drive appears.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .