|
|
Title | Map a network drive |
Description | This example shows how to map a network drive in Visual Basic 6 by using the WNetAddConnection API function. |
Keywords | map drive, network, network drive, drive |
Categories | Files and Directories, Windows |
|
|
Thanks to Mike Marseglia.
The program uses the WNetAddConnection API function, passing it the share name, local drive name, and password if necessary.
|
|
Private Sub cmdMapDrive_Click()
Dim drive_letter As String
Dim share_name As String
Dim password As String
lblResult.Caption = "Working..."
Screen.MousePointer = vbHourglass
DoEvents
drive_letter = txtDriveLetter.Text
If InStr(drive_letter, ":") = 0 _
Then drive_letter = drive_letter & ":"
share_name = txtShareName.Text
password = txtPassword.Text
If WNetAddConnection(share_name, password, _
drive_letter) > 0 _
Then
lblResult.Caption = "Error mapping drive"
Else
lblResult.Caption = "Drive mapped"
End If
Screen.MousePointer = vbDefault
End Sub
|
|
|
|
|
|