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:
And this is in my form (frmMain):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
I may be overlooking something that is already in my code (perhaps in the NETRESOURCE section)... That wouldn't be unusual.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





Reply With Quote