Jump to content

Renaming Local Mapped Drives


Recommended Posts

I found some code on this site that suggested how to rename mapped drives, but doesn't seem to work for me. What am I doing wrong and how can I troubleshoot to make this work in Autoit? - Thanks

$driveLetter = "X:"
$RemoteShare = "\\RemoteName\c$"
DriveMapDel( $driveLetter )
DriveMapAdd($driveLetter, $RemoteShare)

$oShell = ObjCreate("shell.application")
$oShell.NameSpace($driveLetter).Self.Name = "New Name c$"

MsgBox(0,"Mapped Share","Completed")

I found some code in vbs that works, but I would like to strictly do it in Autoit:

Option Explicit
Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName
' 
strDriveLetter = "Y:" 
strRemotePath = "\\RemoteName\c$" 
strNewName = "New Name c$ ver2"

' 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 script.
Link to comment
Share on other sites

I think this can be more easy, try following console command :)

net use <drive:> \\<Servername>\<sharingname>

You can make an AutoIt script, using :

Run(@ComSpec & " /c " & 'net use x: \\servername\sharename', "", @SW_HIDE)
Edited by Matrix112
Link to comment
Share on other sites

@JusGellin

This works for me,

Dim $objNetwork, $strDrive, $objShell, $objUNC
Dim $strRemotePath, $strDriveLetter, $strNewName

$strDriveLetter = "Z:" 
$strRemotePath = "\\SERVER\Sharename$" 
$strNewName = "New Name c$ ver2"

; Section to map the network drive
$objNetwork = ObjCreate("WScript.Network") 
$objNetwork.MapNetworkDrive ($strDriveLetter, $strRemotePath)

; Section which actually (re)names the Mapped Drive
$objShell = ObjCreate("Shell.Application")
$objShell.NameSpace($strDriveLetter).Self.Name = $strNewName

ConsoleWrite( "Check : " & $strDriveLetter & " for " & $strNewName & @CRLF)

regards

ptrex

Link to comment
Share on other sites

Thanks for trying this. After I saw your success, I looked further and found that for some reason certain drive letters were not updating with a new name. It just so happened that the one I was testing was the one that wouldn't update with a new name. But when I tried other mapped drive letters it would work. Also my original as well as your code would work.

I'm just not sure why some drive letters don't seem to get the rename even if I refresh or when I bring up windows explorer fresh again.

Thanks again

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...