How to open Map Network Drive using a button

rbc827

Member
Joined
May 7, 2007
Messages
17
Programming Experience
Beginner
I searched and searched and searched for this answer and it took me 2 days to figure it out, so I figured I would share to those who are in the same boat as I was. I wanted to simply click a button in my app to open the Map Network Drive screen in Microsoft rather than build my own map drive function. Here it is.

Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hWnd As Integer, ByVal dwType As Integer) As Long
Declare Function WNetDisconnectDialog Lib "mpr.dll" Alias "WNetDisconnectDialog" (ByVal hwnd As Integer, ByVal dwType As Integer) As Long
Private Const RESOURCETYPE_DISK = &H1

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim hwnd As Integer
WNetConnectionDialog(hwnd, RESOURCETYPE_DISK)

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim hwnd As Integer
WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK)
 
Back
Top