Roberto Alves

Scripting and server based computing

.VBS for change mapped drivers

This script is very useful with File Servers migration, when can be used at logon script identifying the mapped drivers of each workstation and changing theirs for new drivers.
You can just change variables Path_antigo by name of the old File Server and Path_novo by name of new file server.
On Error Resume Next

Path_name = “Diretório Teste”
Const HKEY_CURRENT_USER = &H80000001
if iDebug then msgbox “Path_antigo: ” & Path_antigo
Set objWMIService=GetObject(“winmgmts:.rootcimv2″)
Set colDisks = objWMIService.ExecQuery(“Select * from Win32_NetworkConnection”)
if iDebug then msgbox “# Discos: ” & colDisks.count
Set WshNetwork = WScript.CreateObject(“WScript.Network”)
Set objShell = CreateObject(“Shell.Application”)
Set WshShell = createobject(“WScript.Shell”)
‘Set objRegistry=GetObject(“winmgmts:.rootdefault:StdRegProv”)
‘strKeyPath = “Network”
‘objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys
‘strValueName = “RemotePath”
”if iDebug then msgbox “Chave Registro: ” & objRegistry.Name
For Each objDisk In colDisks
Letra = objDisk.LocalName
strMapeamento = objDisk.RemoteName
if iDebug then msgbox “Disco: ” & Letra & vbNewLine & “Mapeamento Atual: ” & strMapeamento
If instr(ucase(strMapeamento),ucase(Path_antigo)) then
Caminho = Replace(ucase(strMapeamento),ucase(path_antigo),ucase(path_novo))
if iDebug then msgbox “Disco: ” & Letra & vbNewLine & “Mapeamento Novo: ” & Caminho
WShNetwork.RemoveNetworkDrive Letra, True
If Err.Number <> 0 Then
WshShell.Run “NET USE ” & Letra & ” /DELETE”,0,true
End If
WShNetwork.MapNetworkDrive Letra, Caminho
If Err.Number <> 0 Then
WshShell.Run “net use” & Letra & ” ” & Caminho,0,true
End If
objShell.NameSpace(Letra).Self.Name = Path_name
End if
Category: Scripts

Your email address will not be published. Required fields are marked *