How to make vbs loginscript check that mapped drive exists

ATHENA_IT used Ask the Experts™
Hello experts :)

I am facing a problem, makeing the correct vbs commands in my script.

I want to make the login script, which only purpose is to map some shared folders as drives.
I have made the script below already, but my problem is, that if ex. drive P: exists, an error turns up saying that it is already in use. I would like to know how I can make it just pass by, if the drive letter already is in use ?

Option Explicit
Dim DriveLetter1, DriveLetter2, RemotePath1, RemotePath2
Dim objNetwork
Set objNetwork = CreateObject("WScript.Network")

DriveLetter1 = "X:"
DriveLetter2 = "P:"

RemotePath1 = "\\server1\scan"
RemotePath2 = "\\server2\company"

objNetwork.MapNetworkDrive DriveLetter1, RemotePath1
objNetwork.MapNetworkDrive DriveLetter2, RemotePath2


Thank you in advance :)
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Add the command

On Error Resume Next

immediately before the lines where you actually map the drives.  This instructs the script engine to ignore errors.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial