OpenNTF.org - tests for network drive mappin
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
tests for network drive mapping and maps drives if needed 
Rating:
Not Rated Yet 
Contributor:
Joseph LeMay 
Category:
Lotusscript, VB 
Type:
Network 
Document Release:
Notes Version:
R6.x, R8.x, R5.x, R7.x 
Last Modified:
28 Jul 2009 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Option Public

Option Declare

Dim mappedDrives As Boolean
Sub Initialize
Call mapNetworkDrives
If Not mappedDrives Then Exit Sub
End Sub
Sub mapNetworkDrives
Dim network As Variant
Set network = createobject("WScript.Network")
Dim drivesAreGood As Boolean
drivesAreGood = checkMapping("h:", "\\emrml01\projects") 'substitute your own drive letter and UNC path here.

If drivesAreGood Then
Messagebox "Drive H is mapped to \\emrml01\Projects",0,"Drive mapped correctly"
mappedDrives = True
Else
Messagebox "Drive H is not mapped to \\emrml01\Projects. I will now attempt to map it myself.",0,"Drive not mapped correctly"
Call network.MapNetworkDrive("H:", "\\emrml01\Projects")
'see if we were able to connect
If checkMapping("h:", "\\emrml01\projects") Then
Messagebox "I did it!! Drive H is mapped to \\emrml01\Projects",0,"Drive mapped correctly"
mappedDrives = True
Else
Messagebox "Can't map the drive. Your H drive must be mapped to \\emrml01\Projects to proceed. Please connect to the network.",0,"Stopping"
End If
End If

End Sub
Function checkMapping(driveLetterCheck As String, uncCheck As String) As Boolean
'given drive letter and unc path, check to make sure it's mapped OK.
Dim i As Integer
Dim drives As Variant
Dim net As Variant
Dim networkResult As Variant
Dim driveLetter As String
Dim unc As String
Dim drivesAreGood As Boolean

Set net = createobject("WScript.Network")
Set drives = net.EnumNetworkDrives()
checkMapping = False

For i = 0 To drives.Count() - 1 Step 2
driveLetter = Lcase(drives.Item(i))
unc = Lcase(drives.Item(i+1))
If driveLetter = driveLetterCheck And unc = uncCheck Then
checkMapping = True
Exit For
End If
Next
End Function

Usage / Example
Works on Win32 platforms. Substitute your own drive letter and UNC path name, it will check if that drive letter is mapped to that UNC path. If not, it will attempt to map the drive on it's own.
Code Attachments
mapDrives.lss (2 Kbytes)
 Comments
Posted by Karl-Henry Martinsson on 07/30/2009 03:57:41 PMDoes not work in Notes R5.x
You have it specified as working in R5.x, "boolean" was not introduced until 6.0...
You could declare the variables as integer instead, then it works in R5.x as well.
Posted by Joseph LeMay on 07/30/2009 04:27:45 PMI didn't know that about boolean
you're right, I didn't test in R5. Tried removing the R5 check box, but it's not taking.
 Add your comment!