I've been seeing lots of questions on this in the forums on the MIC support site, so I thought I'd provide an example of how to do this via a resource (VBS) file. Naturally, this can be hacked up and used a needed.
Public Function MapRemoteDrive(ByVal strDriveLetter, ByVal strPath)
'***************************************************************************
'* Name: MapRemoteDrive
'* Author: Theo Moore
'* Assumptions: None
'* Inputs:
'* - strDriveLetter - Drive letter to use
'* - strPath - The path to which you want to map
'*
'* Outputs:
'* - None
'*
'* Notes: If the path to which you are mapping requires a user name and password,
'* it should be included in the strPath param using the following example:
'* /user:
'****************************************************************************
Dim objShell 'As Object
Dim objFSO 'As FileSystemObject
Dim lngCount 'As Long
Dim blnFail 'As Boolean
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Create the correct path based on date:
blnFail = False
'Make sure to remove any other Z: drive
Do
'Track number of attempts
objShell.Run "net.exe use " & strDriveLetter & " /delete", 0, True
lngCount = lngCount + 1
Wait(2)
If lngCount = 5 Then
blnFail = True
lngCount = 0 'Reset for the next loop
Exit Do
End If
Loop Until Not objFSO.DriveExists("Z:")
If blnFail = False Then 'We know the disconnect went correctly
Do Until objFSO.DriveExists("Z:")
objShell.Run "net.exe use " & strDriveLetter & " " & strPath
lngCount = lngCount + 1
Wait(2)
If lngCount = 5 Then 'Something went wrong
blnFail = True
lngCount = 0
Exit Do
End If
Loop
End If
Set objShell = Nothing
Set objFSO = Nothing
'Flip the value of blnFail to
'make it more user readable.
MapRemoteDrive = Not blnFail
End Function
Public Function DisconnectRemoteDrive(strDriveLetter)
'***************************************************************************
'* Name: DisconnectRemoteDrive
'* Author: Theo Moore
'* Assumptions: None
'* Inputs:
'* - strDriveLetter - Drive letter to use
'*
'* Outputs:
'* - None
'*
'* Notes: Simply disconnects the remote drive as indicated by the strDriveLetter
'****************************************************************************
Dim blnFail 'As Boolean
Dim objShell 'As Shell
Dim objFSO 'As Scripting.FileSystemObject
Dim lngCount 'As Long
blnFail = False
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Do
'Track number of attempts
objShell.Run "net.exe use " & strDriveLetter & " /delete", 0, True
lngCount = lngCount + 1
Wait(2)
If lngCount = 5 Then
blnFail = True
lngCount = 0 'Reset for the next loop
Exit Do
End If
Loop Until Not objFSO.DriveExists("Z:")
Set objShell = Nothing
Set objFSO = Nothing
DisconnectRemoteDrive = Not blnFail
End Function