![]()
![]()
Declare Function WNetAddConnection2()Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByVal lpNetResource As NETRESOURCE(), ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
![]()
Declare Function WNetCancelConnection2()Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
![]()
![]()
Structure NETRESOURCEStructure NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
![]()
![]()
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ne(0) As NETRESOURCE, i As Integer
ne(0).dwType = 1
ne(0).lpLocalName = "z:"
ne(0).lpRemoteName =" \\gisserver\zhm"
i = WNetAddConnection2(ne, "gis", "administrator", 1)
Select Case i
Case 0
MessageBox.Show("映射成功!", "映射网络驱动器 ", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Case 85
MessageBox.Show("映射失败,驱动器名已存在 ", "映射网络驱动器", MessageBoxButtons.OK, MessageBoxIcon.Error)
'断开映射
'WNetCancelConnection2("z:", 1, 1)
Case 1202, 1203
MessageBox.Show("映射失败,找不到网络路径 ", "映射网络驱动器", MessageBoxButtons.OK, MessageBoxIcon.Error)
Case 1326
MessageBox.Show("映射失败,登陆账号有误 ", "映射网络驱动器", MessageBoxButtons.OK, MessageBoxIcon.Error)
Case Else
MessageBox.Show("其他错误 ", "映射网络驱动器", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
End Sub