星期六

用指定账号访问局域网内共享文件夹

 


    
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByVal lpNetResource As NETRESOURCE(), ByVal lpPassword As StringByVal lpUserName As StringByVal dwFlags As IntegerAs Integer
    
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As StringByVal dwFlags As IntegerByVal fForce As IntegerAs Integer

    
Structure 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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
Dim ne(0As 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 12021203
                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

posted on 2006-06-06 13:56  星期六  阅读(1594)  评论(0)    收藏  举报