September 24, 2018
Hot Topics:

Add a Network Drive

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »
This tip shows you how to add a new mapped network drive to the local computer in your code:
Option Explicit

Declare Function WNetAddConnection_
Lib "mpr.dll" Alias_
(ByVal lpszNetPath_As String,_
ByVal lpszPassword As String,_
ByVal lpszLocalName As String)_
As Long

Declare Function_
Lib "mpr.dll" Alias_
(ByVal lpszName As String, ByVal_
bForce As Long) As Long

Const WN_SUCCESS = 0_
' The function was successful.
Const WN_NET_ERROR = 2_
' An error occurred on the network.
' The password was invalid.

Function AddConnection(MyShareName_
As String, MyPWD As _String,_
UseLetter As String) As Integer

On Local Error GoTo_

AddConnection = WNetAddConnection_
(MyShareName, MyPWD, UseLetter)

Exit Function
AddConnection = Err
MsgBox Error$
Resume AddConnection_End
End Function

Private Sub cmdAdd_Click()
AddConnection txtShareName.Text,_
txtPassword.Text ,_
End Sub

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date