VB Code:
Public Function m_mapDrive(LocalDrive As String, _
RemoteDrive As String, Optional UserName As String, _
Optional Password As String) As Boolean
'Example:
'MapDrive "Q:", "\\RemoteMachine\RemoteDirectory", _
'"MyLoginName", "MyPassword"
Dim NetR As NETCONNECT
NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = Left$(LocalDrive, 1) & ":"
NetR.lpRemoteName = RemoteDrive
m_mapDrive = (WNetAddConnection2(NetR, UserName, Password, _
CONNECT_UPDATE_PROFILE) = 0)
End Function