supportahm1980
Technical User
Hello I have been getting an error when trying to map a drive that already has been mapped. I would like to check if the drive is mapped do nothing. the problem I have having is with the Or operator. I have two drives I am checking for.
I get the error type mismatch string [S:] on line 20. Can I use a Or on line 20?
Thanks in advance.
I get the error type mismatch string [S:] on line 20. Can I use a Or on line 20?
Thanks in advance.
Code:
Option Explicit
Dim objShell, objNetwork
Dim DriveLetter1, DriveLetter2, RemotePath1, RemotePath2
Dim AllDrives, AlreadyConnected, Network1, Network2, i
Set Network1 = CreateObject("WScript.Network")
DriveLetter1 = "Q:"
DriveLetter2 = "S:"
RemotePath1 = "\\path\shared"
RemotePath2 = "\\path\shared\netscanner"
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set AllDrives = objNetwork.EnumNetworkDrives()
AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2
If AllDrives.Item(i) = DriveLetter1 Or DriveLetter2 Then AlreadyConnected = True
Next
If AlreadyConnected = True then
'do nothing
Else
objNetwork.MapNetworkDrive DriveLetter1, RemotePath1
objNetwork.MapNetworkDrive DriveLetter2, RemotePath2
'objShell.PopUp "Drive " & DriveLetter1 & " connected 'successfully."
End if
Wscript.Quit