Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following batch script which is successfully mapping a few of our drives for our users:

@echo off
net use * /delete /yes
net use x: \\192.168.1.52\xrays
net use s: \\192.168.1.52\common
net use p: \\192.168.1.52\public
net use o: \\192.168.1.52\office
net use y: \\192.168.1.52\drives
EXIT

The mapped drives are taking their names from the share name themselves. However, it would be really handy if I could override the name to something more useful to the users.

I have looked at quite a few documents online with examples of the net use commands, but I can only see options such as credentials but nothing to do with the naming.

The script is being run on Windows XP and Windows 7 workstations.

Any help would be appreciated.

share|improve this question

3 Answers 3

There is no way to do this using only the net use command (see documentation), but there is a way to do this using a vb script, as described by Guy Thomas at computerperformance.co.uk here

In case his Guy's site disappears later, here is his a copy of his script:

' NameDrive.vbs
' VBScript to map a network drive.
' Authors Guy Thomas and Barry Maybury
' Version 1.4 - April 2010
' ----------------------------------------'
'
Option Explicit
Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName
'
strDriveLetter = "W:"
strRemotePath = "\\192.168.1.2\example\sharename"
strNewName = "Example Readable Label"

' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath

' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName

Wscript.Echo "Check : "& strDriveLetter & " for " & strNewName
WScript.Quit

' End of Example VBScript.

Note:

  • If W: doesn't work for you, try W:\ (with the slash)
  • This method will set the drive letter label permanently, i.e. if you later connect another share to the same drive letter, that new share will also get the old label. This can be fixed by either always using this script when connecting shares, or by deleting a key in the registry to revert to normal behaviour.

Reverting to normal behaviour:

  • Launch regedit and then click on Edit (menu) -> Find -> Example Readable Label
  • Or navigate in regedit to HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2 -> _LabelFromReg
  • Just delete the value - leave it blank. The result will be that future drive mapping will revert to the traditional style of mapping.

All of this is more thouroguhly described at Guy's website.

share|improve this answer

There is way to do it from the command line without using VBScript. You can edit the registry using the reg add command. IMHO, doing it this way will be better than using VBScript to change the label because it will not associate the label with the drive letter, but rather it will associate the label with the share. So, if the end user later disconnects X: and manually mounts the xrays share to say the R: drive, then the label will still show up correctly (to whatever you assigned it in the script).

The key you will be writing to is HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\ with the sub-key being the share path with all of the backslashes replaced with pound symbols (#).

Note: I have not yet tested how you should handle share names with spaces (or even pound symbols) in them.

@echo off

net use * /delete /yes

:: Set the label in the registry
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##192.168.1.52#xrays /v _LabelFromReg /t REG_SZ /f /d "X-Rays"
:: Map the drive
net use x: \\192.168.1.52\xrays

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##192.168.1.52#common /v _LabelFromReg /t REG_SZ /f /d "Common"
net use s: \\192.168.1.52\common

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##192.168.1.52#public /v _LabelFromReg /t REG_SZ /f /d "Public"
net use p: \\192.168.1.52\public

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##192.168.1.52#office /v _LabelFromReg /t REG_SZ /f /d "Office"
net use o: \\192.168.1.52\office

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##192.168.1.52#drives /v _LabelFromReg /t REG_SZ /f /d "Drives"
net use y: \\192.168.1.52\drives

EXIT
share|improve this answer
    
This is great, as it doesn't need VBScript to be done. Thank you. –  Zulakis Sep 10 at 10:37
@echo off
echo --------------------------delete map drive all------------------------
net use * /delete /yes
echo ------------------create drive --------------------------------
net use m: \\172.16.0.136\Source /user:aleg\masr masr2006*
net use n: \\172.16.0.136\scanner_bat_test /user:alwq\4288044 masr2006*
echo ---------------------------------------------------

EXIT
share|improve this answer
1  
Welcome to Super User! Please edit your post and explain what the code does exactly. Also check our formatting help and use the preview to take a look at your posts before submitting. You have to indent code by 4 spaces. –  slhck Dec 16 '12 at 11:20
1  
Thanks, could you explain what each line does. It's hard to distinguish which parts are the passwords and drive names etc. –  dannymcc Dec 17 '12 at 0:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.