Results 1 to 2 of 2

Thread: Help with mapping a drive (persistence)

  1. #1

    Thread Starter
    Member FrogBoy666's Avatar
    Join Date
    Aug 2000
    Location
    Columbia, SC
    Posts
    34
    I'm currently using "WNetAddConnection2" to map a network drive, but the all of the connections are persistent. I was wondering if there was some way to make the mapping non-persistent (i.e., ensure that my computer doesn't try to reconnect during the next logon to WinNT).

    Here is my code (in case you need it):

    This is in a module:
    Code:
    Option Explicit
    
    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
    
    ' error values
    Public Const ERROR_SESSION_CREDENTIAL_CONFLICT = 1219&
    Public Const ERROR_INVALID_PASSWORDNAME = 1216&
    Public Const ERROR_ACCESS_DENIED = 5&
    Public Const ERROR_BAD_DEVICE = 1200&
    Public Const ERROR_BAD_PROFILE = 1206&
    Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
    Public Const ERROR_DEV_NOT_EXIST = 55&
    Public Const ERROR_ALREADY_ASSIGNED = 85&
    Public Const NO_ERROR = 0
    
    Public Const RESOURCETYPE_DISK As Long = &H1& 'dwType
    
    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 Const CONNECT_UPDATE_PROFILE As Long = &H1&
    
    Public netRes As NETRESOURCE
    Public lResult As Long
    And this is in my form (frmMain):
    Code:
    Private Sub Command1_Click()
    
        Dim strDriveLetter, strNetResName As String
        Dim strPswd, strUser As String
    
        strDriveLetter = "K:" + Chr$(0)
        strNetResName = "\\network\path" + Chr(0)
    
        With netRes
            .dwType = RESOURCETYPE_DISK
            .lpLocalName = strDriveLetter
            .lpRemoteName = strNetResName
            .lpProvider = ""
        End With
    
        strUser = "UserName"
        strPswd = "Password"
    
        lResult = WNetAddConnection2(netRes, strPswd, strUser, CONNECT_UPDATE_PROFILE)
                    '// update profile with connect information
    
        ' check for errors using const's defined above
        Select Case lResult
            Case NO_ERROR
                ' No problems occurred...
    
            Case Else
                'Handle any problems that occur
        End Select
    
    End Sub
    I may be overlooking something that is already in my code (perhaps in the NETRESOURCE section)... That wouldn't be unusual.

  2. #2
    New Member
    Join Date
    Jan 2001
    Location
    Canberra, Australia
    Posts
    11

    Talking dwflags

    Hope this helps - I copied it from the API Guide program.


    · dwFlags
    A set of bit flags that specify connection options. The following bit flag constant is currently defined:
    CONNECT_UPDATE_PROFILE
    The network resource connection should be remembered.

    If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on.
    The operating system remembers only successful connections that redirect local devices. It does not remember unsuccessful connections or deviceless connections. A deviceless connection occurs when lpLocalName is NULL or points to an empty string.
    If this bit flag is clear, the operating system will not automatically restore the connection at logon.

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