VB Code:
  1. Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszstrPassword As String, ByVal lpszLocalName As String) As Long
  2.  
  3. Dim strLocalDriveLetter As String
  4.  
  5. Dim strPassword As String
  6.  
  7. Dim strNetworkPathName As String
  8.  
  9.     strLocalDriveLetter = "Z:"                  'Local drive letter to be mapped
  10.  
  11.     strPassword = ""                            'specify network password if required
  12.  
  13.     strNetworkPathName = "\\NEWPATH\NEWPATH"   'path to network drive
  14.    
  15.     If WNetAddConnection(strNetworkPathName, strPassword, strLocalDriveLetter) > 0 Then
  16.  
  17.         MsgBox ("An Error occurred mapping the drive")
  18.  
  19.     Else
  20.  
  21.         MsgBox ("Drive successfully mapped!")
  22.  
  23.     End If