Link to home
Start Free TrialLog in
Avatar of darren100
darren100

asked on

How Do You Map Network Drives in VB?

How do you map and disconnect network drives in VB?

The following code doesn't seem to work:

#If Win32 Then
     Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As Long
     Declare Function WNetDisconnectDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As Long
#End If
 
Private Sub netdrivebutton_Click(Index As Integer)
     Dim i As Long
     Select Case Index
     Case 0  'Map To is Selected
         #If Win32 Then
             i = WNetConnectionDialog(Me.hWnd, RESOURCETYPE_DISK)
             If i <> 0 And i <> -1 And i <> 1223 Then
                 MsgBox "Error: " & i, 48, 1
             End If
         #End If
     Case 1  'Disconnect is Selected
         #If Win32 Then
             i = WNetDisconnectDialog(Me.hWnd, RESOURCETYPE_DISK)
         #End If
     End Select
End Sub
ASKER CERTIFIED SOLUTION
Avatar of KEWL
KEWL

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have given you complete VB code in the following question :

https://www.experts-exchange.com/topics/comp/lang/visualbasic/Q.10073988

It uses API, no shell to extern app and works very well.
Avatar of KEWL
KEWL

although i want the points, waty's API would be a better choice