By the way, here's the code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias _ | |
"WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword _ | |
As String, ByVal lpszLocalName As String) As Long | |
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias _ | |
"WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) _ | |
As Long | |
Sub Test() | |
Dim sDriveLetter As String | |
Dim sShareName As String | |
Dim sPassword As String | |
sDriveLetter = "G:" | |
sShareName = "\\Server1\Filearea1" | |
sPassword = "" | |
If WNetCancelConnection(sDriveLetter, 0) Then | |
MsgBox "Error disconnecting mapped drive" | |
Else | |
MsgBox "Drive mapping disconnected" | |
End If | |
If WNetAddConnection(sShareName, sPassword, sDriveLetter) > 0 Then | |
MsgBox "Error mapping drive" | |
Else | |
MsgBox "Drive mapped" | |
End If | |
End Sub |
Komentar