Aqui está uma função que estou usando:
Function MapDrive(ByVal strDrive, ByVal strShare)
' Function to map network share to a drive letter.
' If the drive letter specified is already in use, the function
' attempts to remove the network connection.
' objFSO is the File System Object, with global scope.
' objNetwork is the Network object, with global scope.
' Returns True if drive mapped, False otherwise.
Dim objDrive
On Error Resume Next
If (objFSO.DriveExists(strDrive) = True) Then
Set objDrive = objFSO.GetDrive(strDrive)
If (Err.Number <> 0) Then
On Error GoTo 0
MapDrive = False
Exit Function
End If
If (objDrive.DriveType = 3) Then
objNetwork.RemoveNetworkDrive strDrive, True, True
Else
MapDrive = False
Exit Function
End If
Set objDrive = Nothing
End If
objNetwork.MapNetworkDrive strDrive, strShare
If (Err.Number = 0) Then
MapDrive = True
Else
Err.Clear
MapDrive = False
End If
On Error GoTo 0
End Function
Exemplo de uso:
If (MapDrive("Z:", "\yourserver\yourshare") = False) Then
' Do something because there was an error.
End If