你可以调用WNetConnectionDialog函数，这个函数将显示标准的映射对话框。该函数只有两个参数，第一个为调用该函数的窗口句柄，第二个参数为RESOURCETYPE_DISK。 
    另外，你也可以不显示对话框直接WNetAddConnection2映射驱动器。下面是一个例子： 
    1、建立一个标准的EXE工程。 
    2、添加一个模块到工程。 
    3、复制并粘贴下面的代码到新添加的模块： 
     Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _ 
     "WNetAddConnection2A" (lpNetResource As NETRESOURCE, _ 
     ByVal lpPassword As String, ByVal lpUserName As String, _ 
     ByVal dwFlags As Long) As Long 
     
     Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _ 
     "WNetCancelConnection2A" (ByVal lpName As String, _ 
     ByVal dwFlags As Long, ByVal fForce As Long) As Long 
     
     Type NETRESOURCE 
     dwScope As Long 
     dwType As Long 
     dwDisplayType As Long 
     dwUsage As Long 
     lpLocalName As String 
     lpRemoteName As String 
     lpComment As String 
     lpProvider As String 
     End Type 
     
     Public Const NO_ERROR = 0 
     Public Const CONNECT_UPDATE_PROFILE = &H1 
     ' The following includes all the constants defined for NETRESOURCE, 
     ' not just the ones used in this example. 
     Public Const RESOURCETYPE_DISK = &H1 
     Public Const RESOURCETYPE_PRINT = &H2 
     Public Const RESOURCETYPE_ANY = &H0 
     Public Const RESOURCE_CONNECTED = &H1 
     Public Const RESOURCE_REMEMBERED = &H3 
     Public Const RESOURCE_GLOBALNET = &H2 
     Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1 
     Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0 
     Public Const RESOURCEDISPLAYTYPE_SERVER = &H2 
     Public Const RESOURCEDISPLAYTYPE_SHARE = &H3 
     Public Const RESOURCEUSAGE_CONNECTABLE = &H1 
     Public Const RESOURCEUSAGE_CONTAINER = &H2 
     ' Error Constants: 
     Public Const ERROR_ACCESS_DENIED = 5& 
     Public Const ERROR_ALREADY_ASSIGNED = 85& 
     Public Const ERROR_BAD_DEV_TYPE = 66& 
     Public Const ERROR_BAD_DEVICE = 1200& 
     Public Const ERROR_BAD_NET_NAME = 67& 
     Public Const ERROR_BAD_PROFILE = 1206& 
     Public Const ERROR_BAD_PROVIDER = 1204& 
     Public Const ERROR_BUSY = 170& 
     Public Const ERROR_CANCELLED = 1223& 
     Public Const ERROR_CANNOT_OPEN_PROFILE = 1205& 
     Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202& 
     Public Const ERROR_EXTENDED_ERROR = 1208& 
     Public Const ERROR_INVALID_PASSWORD = 86& 
     Public Const ERROR_NO_NET_OR_BAD_PATH = 1203& 
    4、添加两个按钮到Form1：Command1和Command2。 
    5、添加下面的代码到Form1，使用合法的名字替换"\\ServerName\ShareName": 
     Option Explicit 
     
     Private Sub Command1_Click() 
     Dim NetR As NETRESOURCE 
     Dim ErrInfo As Long 
     Dim MyPass As String, MyUser As String 
     
     NetR.dwScope = RESOURCE_GLOBALNET 
     NetR.dwType = RESOURCETYPE_DISK 
     NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE 
     NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE 
     NetR.lpLocalName = "X:" ' If undefined, Connect with no device 
     NetR.lpRemoteName = "\\ServerName\ShareName" ' Your valid share 
     'NetR.lpComment = "Optional Comment" 
     'NetR.lpProvider = ' Leave this undefined 
     
     ' If the MyPass and MyUser arguments are null (use vbNullString), the 
     ' user context for the process provides the default user name. 
     ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _ 
     CONNECT_UPDATE_PROFILE) 
     If ErrInfo = NO_ERROR Then 
     MsgBox "Net Connection Successful!", vbInformation, _ 
     "Share Connected" 
     Else 
     MsgBox "ERROR: " & ErrInfo & " - Net Connection Failed!", _ 
     vbExclamation, "Share not Connected" 
     End If 
     End Sub 
     
     Private Sub Command2_Click() 
     Dim ErrInfo As Long 
     Dim strLocalName As String 
     
     ' You may specify either the lpRemoteName or lpLocalName 
     'strLocalName = "\\ServerName\ShareName" 
     strLocalName = "X:" 
     ErrInfo = WNetCancelConnection2(strLocalName, _ 
     CONNECT_UPDATE_PROFILE, False) 
     If ErrInfo = NO_ERROR Then 
     MsgBox "Net Disconnection Successful!", vbInformation, _ 
     "Share Disconnected" 
     Else 
     MsgBox "ERROR: " & ErrInfo & " - Net Disconnection Failed!", _ 
     vbExclamation, "Share not Disconnected" 
     End If 
     End Sub 
<END>