Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Map drive logic 1

Status
Not open for further replies.

supportahm1980

Technical User
May 30, 2006
208
US
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.
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
 
If AllDrives.Item(i) = DriveLetter1 Or AllDrives.Item(i) = DriveLetter2 Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top