API Tip Map Network Drives Easily
As far as I know, there isn't a single control that comes with VB that would enable you to call up drive mapping dialog. However you should have no problem doing it yourself. Just use two API functions - WNetConnectionDialog and WNetDisconnectDialog. The first one let's you map a network drive (makes a network hard drive look and feel as one of your local hard drives) and the second one disconnects network resources (hard drives).
Picture 1: Calling WNetConnectionDialog results in this dialog box Let's have a close look at the functions: Public Declare Function WNetConnectionDialog Lib "mpr.dll" Alias
"WNetConnectionDialog" (ByVal hwnd As Long, ByVal dwType As Long) As Long Public Declare Function WNetDisconnectDialog Lib "mpr.dll" Alias "WNetDisconnectDialog" (ByVal hwnd As Long, ByVal dwType As Long) As Long Public Const RESOURCETYPE_DISK = &H1 ' connect to
network hard drives That's all API declarations you need. In the following example I added two command buttons, cmdConnect and cmdDisconnect for adding or removing network resources when the buttons are clicked: Private Sub cmdConnect_Click() By clicking cmdConnect, a user of your app can map network hard drive and by clicking cmdDisconnect, a user can disconnect network hard drive. Simple and powerful! Good luck and be sure to save your work before you mess around with Windows (r) API.
Written By Laimonas Simutis. 2001. laijerrad@yahoo.com
Written By Laimonas Simutis. 2002. laijerrad@yahoo.com |