Results 1 to 4 of 4

Thread: WNetAddConnection2 Problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Winnipeg, MB, Canada
    Posts
    3

    Unhappy

    I am having some trouble with getting WNetAddConnection2 API call in vb6 to work with any UserID other than a user that is in the Administrator Group. The error code that is returned by the system is always 1208. Here is the Code I'm using:

    ========================================================

    Public 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

    Public Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" _
    (ByVal lpName As String, _
    ByVal dwFlags As Long, _
    ByVal fForce As Long) _
    As Long


    Public Const ERROR_NOT_CONNECTED = 2250&
    Public Const ERROR_EXTENDED_ERROR = 1208&
    Public Const ERROR_MORE_DATA = 234
    Public Const ERROR_ACCESS_DENIED = 5&
    Public Const ERROR_ALREADY_ASSIGNED = 85&
    Public Const ERROR_BAD_NET_NAME = 67&
    Public Const ERROR_BAD_DEV_TYPE = 66&
    Public Const ERROR_BUSY = 170&
    Public Const ERROR_CANNOT_OPEN_PROFILE = 1205&
    Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
    Public Const ERROR_INVALID_PASSWORD = 86&
    Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
    Public Const ERROR_NO_NETWORK = 1222&


    Public Const RESOURCETYPE_ANY = &H0
    Public Const RESOURCETYPE_DISK = &H1
    Public Const RESOURCETYPE_PRINT = &H2

    Public Const CONNECT_UPDATE_PROFILE = &H0

    Public 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


    Dim lRes&, sRes$, sPass$, sUser$
    Dim udtNet As NETRESOURCE
    _______________________________

    Sub ConnectDrive()

    With udtNet
    .dwType = RESOURCETYPE_DISK
    .lpLocalName = "W:" & Chr(0)
    .lpRemoteName = "\\ServerName\HiddenShareName$" & Chr(0)
    End With

    sUser = "NonAdministrativeUser" & Chr(0)
    sPass = "password" & Chr(0)

    lRes = WNetAddConnection2(udtNet, ByVal sPass, ByVal sUser, CONNECT_UPDATE_PROFILE)

    End Sub
    ____________________________________

    Sub DisconnectDrive()

    lRes = WNetCancelConnection2("W:", CONNECT_UPDATE_PROFILE, False)


    End Sub

    ==========================================================

    Can anyone offer some insight into either solving the problem or finding out how to get the Extended Error Information?

    Thanks in Advance.

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    this reply is a bit late, but I found the question when I searched for something similar. If you still need an answer, you can try the following:
    According to the MSDN library, the error is network specific. You can call WNetGetLastError to get additional information about the specific error.

    Public Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError As Long, ByVal lpErrorBuf As String, ByVal nErrorBufSize As Long, ByVal lpNameBuf As String, ByVal nNameBufSize As Long) As Long


  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Winnipeg, MB, Canada
    Posts
    3
    I gave this a try and I cant seem to find the correct way to impliment the wnetgetlasterror... If possible could you provide and example of this.

    Thanks


  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This is out of the blue, because I don't have an error to test it with.
    I think it should work though.

    in a module:
    Code:
    Option Explicit
    
    Public Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError As Long, ByVal lpErrorBuf As String, ByVal nErrorBufSize As Long, ByVal lpNameBuf As String, ByVal nNameBufSize As Long) As Long
    
    Public Function GetLastNetError(ByRef ErrNum, ByRef ErrDesc, ByRef errProvider)
    Dim retVal As Long
    Dim pos As Integer
        ErrDesc = Space(256)
        errProvider = Space(256)
        retVal = WNetGetLastError(ErrNum, ErrDesc, 255&, errProvider, 255&)
        pos = InStr(ErrDesc, Chr(0))
        If pos > 0 Then
            ErrDesc = Left(ErrDesc, pos - 1)
        End If
        pos = InStr(errProvider, Chr(0))
        If pos > 0 Then
            errProvider = Left(errProvider, pos - 1)
        End If
    End Function
    And you could call it like this:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim ErrNo As Long
    Dim ErrDesc As String
    Dim ErrSource As String
        Call GetLastNetError(ErrNo, ErrDesc, ErrSource)
        MsgBox "Error from " & ErrSource & vbCrLf & "No : " & ErrNo & vbCrLf & ErrDesc
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width