MAP NETWORK DRIVE WITH VB

By | 2002-06-01

Well the simple way to map network drives with vb.

Original Author: LEVENT YILDIZ

API Declarations

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

Code

Private Sub cmdConnect_Click()
  Dim x As Long
  x = WNetAddConnection("\CPU1CWINDOWSDESKTOP", "", "R:")
  If x <> 0 Then
    MsgBox "connect failed"
  End If
End Sub
Private Sub cmdDisconnect_Click()
  Dim x As Long
  x = WNetCancelConnection("R:", 0)
  If x <> 0 Then
    MsgBox "Disconnect failed"
  End If
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.