这个应该是你要的了:'API定义
Private Type NETCONNECT
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
Private Const HWND_TOPMOST = -1Private Const CONNECT_UPDATE_PROFILE = &H1Private Const RESOURCE_CONNECTED As Long = &H1&
Private Const RESOURCE_GLOBALNET As Long = &H2&
Private Const RESOURCETYPE_DISK As Long = &H1&
Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long'此函数建立网络映射
Public Function MapNetDrive(ByVal sLocalDrive As String, ByVal sRemoteDir As String, ByVal sUserName As String, ByVal sPassword As String, Optional bForever As Boolean = False) As Boolean
Dim tNet As NETCONNECT
Dim lForever As Long
With tNet
.lpProvider = vbNullString
.dwScope = RESOURCE_GLOBALNET
.dwType = RESOURCETYPE_DISK
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONNECTABLE
.lpLocalName = Left$(sLocalDrive, 1) & ":"
.lpRemoteName = sRemoteDir
End With
lForever = 0
If bForever Then lForever = CONNECT_UPDATE_PROFILE
MapNetDrive = (WNetAddConnection2(tNet, sPassword, sUserName, lForever) = 0)
End Function
'此函数取消网络映射
Public Function UnmapNetDrive(ByVal sConnectName As String, Optional bForever As Boolean = True, Optional bForce As Boolean = False) As Boolean
Dim lFlag As Long
Dim lForce As Long
lFlag = 0
If bForever Then lFlag = CONNECT_UPDATE_PROFILE
lForce = 0
If bForce Then lForce = -1
UnmapNetDrive = (WNetCancelConnection2(sConnectName, lFlag, lForce) = 0)
End Function
Private Type NETCONNECT
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
Private Const HWND_TOPMOST = -1Private Const CONNECT_UPDATE_PROFILE = &H1Private Const RESOURCE_CONNECTED As Long = &H1&
Private Const RESOURCE_GLOBALNET As Long = &H2&
Private Const RESOURCETYPE_DISK As Long = &H1&
Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long'此函数建立网络映射
Public Function MapNetDrive(ByVal sLocalDrive As String, ByVal sRemoteDir As String, ByVal sUserName As String, ByVal sPassword As String, Optional bForever As Boolean = False) As Boolean
Dim tNet As NETCONNECT
Dim lForever As Long
With tNet
.lpProvider = vbNullString
.dwScope = RESOURCE_GLOBALNET
.dwType = RESOURCETYPE_DISK
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONNECTABLE
.lpLocalName = Left$(sLocalDrive, 1) & ":"
.lpRemoteName = sRemoteDir
End With
lForever = 0
If bForever Then lForever = CONNECT_UPDATE_PROFILE
MapNetDrive = (WNetAddConnection2(tNet, sPassword, sUserName, lForever) = 0)
End Function
'此函数取消网络映射
Public Function UnmapNetDrive(ByVal sConnectName As String, Optional bForever As Boolean = True, Optional bForce As Boolean = False) As Boolean
Dim lFlag As Long
Dim lForce As Long
lFlag = 0
If bForever Then lFlag = CONNECT_UPDATE_PROFILE
lForce = 0
If bForce Then lForce = -1
UnmapNetDrive = (WNetCancelConnection2(sConnectName, lFlag, lForce) = 0)
End Function
还要再问一下,我想这样实现:一个文本筐控件,用于用户指定映射的盘符,一个按扭控件,单击后可以调出浏览网络资源的对话窗体,请问如何实现?