October 31, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

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_
"WNetAddConnectionA"_
(ByVal lpszNetPath_As String,_
ByVal lpszPassword As String,_
ByVal lpszLocalName As String)_
As Long

Declare Function_
WNetCancelConnection_
Lib "mpr.dll" Alias_
"WNetCancelConnectionA"_
(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.
Const WN_BAD_PASSWORD = 6_
' The password was invalid.



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

On Local Error GoTo_
AddConnection1_Err

AddConnection = WNetAddConnection_
(MyShareName, MyPWD, UseLetter)
AddConnection_End:

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

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





Comment and Contribute

 


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

 

 


Sitemap | Contact Us

Rocket Fuel