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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error checking in a Drive mapping script 1

Status
Not open for further replies.

cohortq

Technical User
Aug 20, 2002
20
US
Hi!! Ok I have this script where I map drives in VB using
WSHNetwork.MapNetworkDrive "O:", "\\new1\Temp dump"
WSHNetwork.MapNetworkDrive "Q:", "\\new1\NMF leads"
but I get an error if it already is mapped. Is there a way I could to see if it is already mapped and if so do nto go through with the mapping process THANX!!!
 
Hi,
Add common error handling to your script:
-------------------
On Error Resume Next
WSHNetwork.MapNetworkDrive "O:", "\\new1\Temp dump"
WSHNetwork.MapNetworkDrive "Q:", "\\new1\NMF leads"
On Error GoTo MapError:

MapError:
MsgBox "An error occurred while maping network drive."
-------------------
I think you should replace the MsgBox with a check for the maped drive and you might even want to unmap the current drive.

Good Luck
Wibbe
 
I use the trick of checking to see if the device file NUL exists. NUL is a special file that exists in every folder. (So you can use it to see if a directory exists, too) I do this all the time in BAT files, and didn't want to bother with a new way when I started writing VBS files. However, the creation of the file system scripting object is probably going to be slower than just letting the network map fail. Also go look at the fso.Drives function. It will return a list of all the currently mapped drives, and the shares they are mapped to. You'll need to go this route if you want to "fix" people who've mapped drives by hand, or assigned local devices to the drives you want to use. Actually, now that I think about it, I have seen a lot of heavy-handed admins force a "RemoveNetworkDrive" for F-Z at the beginning of their scripts.

In BAT:
IF EXIST X:\NUL THEN ECHO X: exists.
IF NOT EXIST X:\NUL THEN ECHO X: is free.


In a VBS:
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists("X:\NUL")) Then
Wscript.Echo "X: is mapped."
Else
WSHNetwork.MapNetworkDrive "Q:", "\\new1\Temp"
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top