Automatically connect to remote shared folder with password

'Automatically connect to remote shared folder with password an non permanent connection strPer = "FALSE"

'And check if folder is already mounted

'Example for 2 shares

Option Explicit
Dim objNetwork, strDrive, objShell, objUNC, objFSO
Dim RemoteShare1, Drive1, NewName1
Dim RemoteShare2, Drive2, NewName2
Dim strPer, strUsr, strPas

 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")

strPer = "FALSE"
strUsr = "test"
strPas = "test pass"

' Drives, Paths, Names

Drive1 = "Z:"
RemoteShare1= "\\192.168.10.1\Share"
NewName1 = "Share"

' Drives, Paths, Names

Drive2= "X:"
RemoteShare2= "\\192.168.10.1\Temporary"
NewName2= "Temporary"

 

' Test for to see if are already mapped, if yes ignore, if no - mapping.

' Map Z network Drive
If (objFSO.DriveExists("Z:") = True) Then
objNetwork.RemoveNetworkDrive "Z:", True, True
End If
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive Drive1, RemoteShare1, strPer, strUsr, strPas

' Renaming Z network Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(Drive1).Self.Name = NewName1

' Test for to see if are already mapped, if yes ignore, if no - mapping.
If (objFSO.DriveExists("X:") = True) Then
objNetwork.RemoveNetworkDrive "X:", True, True
End If
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive Drive2, RemoteShare2, strPer, strUsr, strPas

' Renaming X network Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(Drive2).Self.Name = NewName2


WScript.Quit

' End of VBScript.

 

 

save file .vbs