WNetAddConnection2 - HELP! 
Author Message
 WNetAddConnection2 - HELP!

Here's my code...

     BAS file...
     Declare Function WNetAddConnection2 Lib "mpr.dll" _
         Alias "WNetAddConnection2A" _
               (lpNetResource As NETRESOURCE, _
                ByVal lpPassword As String, _
                ByVal lpUserName As String, _
                ByVal dwFlags As Long) As Long
     Declare Function WNetCancelConnection2 Lib "mpr.dll" _
         Alias "WNetCancelConnection2A" _
               (ByVal lpName As String, _
               ByVal dwFlags As Long, _
               ByVal fForce As Long) As Long

     Type NETRESOURCE
       dwScope As Long
       dwType As Long
       dwDisplayType As Long
       dwUsage As Long
       lpLocalName As String
       lpRemoteName As String
       lpComment As String
       lpProvider As String
     End Type

     -----------------------------------------------------------------
     Form...

     Private Sub Command1_Click()
         Dim NetR As NETRESOURCE
         Dim ErrInfo As Long
         Dim MyPass, MyUser As String

         NetR.dwScope = 2
         NetR.dwType = 1
         NetR.dwDisplayType = 3
         NetR.dwUsage = 1
         NetR.lpLocalName = "U:"
         NetR.lpRemoteName = Trim(Text1.Text)    ' text box
         MyPass = "kgeaug98"
         MyUser = "kcmsgo"
         ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, 0)
         If ErrInfo = 0 Then
             MsgBox "Net Connection Successful"
         Else
             MsgBox "Error: " & ErrInfo & " Connection Failed"
         End If

     End Sub

     Private Sub Command2_Click()
         Dim ErrInfo As Long

         ErrInfo = WNetCancelConnection2(Trim(Text1.Text), 0, True)
         If ErrInfo = 0 Then
             MsgBox "Net disconnection Successful"
         Else
             MsgBox "ERROR: " & ErrInfo & " Net Disconnection Failed"
         End If

     End Sub

     ---------------------------------------------------------------------

What I've found...

    I was using     ErrInfo = WNetCancelConnection2("U:",0,True).

    This was removing the "mapping" of U: in Windows Explorer, but the
connection was still active.  I've changed it to use the NetR.lpRemoteName,
and this cancelled the connection.  So, this problem was resolved.

New problem...I can double click on "Network Neighborhood" and get to a
particular lan by keying in the id "kcmsgo" and the password "kgeaug98" (as
stated above) and this works fine.  However, this API call
WNetAddConnection2 (above) works on some lans and not on others.  The double
clicking, in Network Neighborhood, works on all of the lans.  I'm getting
Error Code of 5 (Access denied).  I don't understand what is happening
different between Windows Explorer (Network Neighborhood) and the
WNetAddConnection2 API call.

Any help would be appreciated.

Thanks!



Mon, 15 Jan 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. WNetAddConnection2 HELP

2. Help: Logging into NT using WNetAddConnection2

3. HELP: WNetAddConnection2 and VB - SOLUTION FOUND

4. Help With WNetAddConnection2

5. WNetAddConnection2 PLEASE HELP!

6. WNetAddConnection2 ...PLEASE HELP

7. Help With WNetAddConnection2

8. WNetAddConnection2 in a service (repost)

9. WNetAddConnection2 in a service

10. DCOM: error 1312 on WNetAddConnection2

11. WNetAddConnection2 API Call ????????

12. WNetAddConnection2 & /user:domain\username

 

 
Powered by phpBB® Forum Software