谁能帮小弟看下这段代码,运行时老出错
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (IpNetResource As NETRESOURCE, ByVal IpPassword As String, ByVal IpUserName As String, ByVal dwFlags As Long) As LongPrivate Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
pLocalName As Long
pRemoteName As Long
pComment As Long
pProvider As Long
End Type
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetAddCancel2A" (ByVal IpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Private Sub Command1_Click() '连接
Dim NR As NETRESOURCE: Dim MyErr As Long
NR.dwScope = RESOURCE_GLOBALNET: NR.dwType = RESOURCETYPE_DISK
NR.dwDisplayType = RESOURCEDISPLAYTYPE_SHADRE
NR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NR.IpLocalName = Text1.Text: NR.IpRemoteName = Text2.Text
MyErr = WNetAddConnection2(NR, Text1.Text, Text2.Text, CONNECT_UPDATE_PROFILE)
If MyErr = NO_ERROR Then
MsgBox "网络驱动器映射成功!", vbInformation, "映射信息提示"
Else
MsgBox "出现错误:" & Err.Description & "- 网络驱动器映射失败!", vbExclamation, "映射信息提示"
End If
End Sub
Private Sub Command2_Click() '退出
End
End Sub
Private Sub Command3_Click() '断开
Dim MyErr As Long: Dim strName As String: strName = Text5.Text
MyErr = WNetCancelConnection2(strName, CONNECT_UPDATE_PROFILE, False)
If MyErr = NO_ERROR Then
MsgBox "成功断开驱动器映射!", vbInformation, "断开信息提示"
Else
MsgBox "出现错误:" & Err.Description & "- 驱动器断开失败!", vbExclamation, "断开信息提示"
End If
End Sub