Sign in to follow this  
Followers 0
JusGellin

Renaming Local Mapped Drives

5 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thanks, I knew how to map a drive. I wanted to rename that mapped drive on my local machine with a new readable name like the vbs does. :)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0