Option Explicit
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" ( _ ByVal lpszNetPath As String, _ ByVal lpszPassword As String, _ ByVal lpszLocalName As String) As Long
Private Sub MapDrive(share_name As String, Optional drive_letter As String = "G", Optional Password As String = "") Me.Caption = "Working..." Screen.MousePointer = vbHourglass DoEvents If InStr(drive_letter, ":") = 0 Then drive_letter = drive_letter & ":" End If If WNetAddConnection(share_name, Password, drive_letter) > 0 Then MsgBox "Error mapping drive" Else MsgBox "Drive mapped" End If Screen.MousePointer = vbDefault End Sub
Private Sub Form_Load() Call MapDrive("\\it100626\API", "G") End Sub |