用 shell "net use ..." 建立连接,如果连接成功的话,再用 filecopy 就行了
Public Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long '映射一个网洛驱动器,并断开 Public 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 Public Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long Public Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long 检查连接》映射网络驱动器为本机盘》操作》关闭连接
Public Type NETRESOURCE dwScope As Long dwType As Long dwDisplayType As Long dwUsage As Long pLocalName As String pRemoteName As String pComment As Long pProvider As Long bIsConnect As Boolean strRomoteTop As String mbIsReady As Boolean End Type Public Function GetDriverName() As String On Error Resume NextDim i As Integer Dim strDriver As String For i = 0 To 25 strDriver = Chr(98 + i) If GetDriveType(strDriver & ":\") = 3 Or GetDriveType(strDriver & ":\") = 5 Then GetDriverName = Chr(98 + i + 1) & ":" End If If GetDriveType(strDriver & ":\") = 4 Then If WNetCancelConnection(strDriver & ":", True) = 0 Then End If End If Next i If Asc(GetDriverName) = 123 Then MsgBox GetYhm(UserDlm) & ",对不起,您的计算机的盘符已经用完,系统无法映射,读取失败!" End IfEnd FunctionPublic Function ConnectServer() As Boolean ConnectServer = False
If WNetAddConnection2(lpNet, strConnectPassWord, vbNull, 0) <> 0 Then If WNetAddConnection2(lpNet, strConnectPassWord, strConnectUserName, 0) <> 0 Then lpNet.bIsConnect = False MsgBox "网络连接错误,请检查网络连接状态!可能是您的电脑没有连入网络或网络配置错误." Exit Function Else ConnectServer = True lpNet.bIsConnect = True End If Else ConnectServer = True lpNet.bIsConnect = True End If
98, 2000 都一样.
在command line 键入
net use [drive:] [resource shared] *
'映射一个网洛驱动器,并断开
Public 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
Public Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
Public Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
检查连接》映射网络驱动器为本机盘》操作》关闭连接
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
pLocalName As String
pRemoteName As String
pComment As Long
pProvider As Long
bIsConnect As Boolean
strRomoteTop As String
mbIsReady As Boolean
End Type
Public Function GetDriverName() As String
On Error Resume NextDim i As Integer
Dim strDriver As String
For i = 0 To 25
strDriver = Chr(98 + i)
If GetDriveType(strDriver & ":\") = 3 Or GetDriveType(strDriver & ":\") = 5 Then
GetDriverName = Chr(98 + i + 1) & ":"
End If
If GetDriveType(strDriver & ":\") = 4 Then
If WNetCancelConnection(strDriver & ":", True) = 0 Then
End If
End If
Next i
If Asc(GetDriverName) = 123 Then
MsgBox GetYhm(UserDlm) & ",对不起,您的计算机的盘符已经用完,系统无法映射,读取失败!"
End IfEnd FunctionPublic Function ConnectServer() As Boolean
ConnectServer = False
If WNetAddConnection2(lpNet, strConnectPassWord, vbNull, 0) <> 0 Then
If WNetAddConnection2(lpNet, strConnectPassWord, strConnectUserName, 0) <> 0 Then
lpNet.bIsConnect = False
MsgBox "网络连接错误,请检查网络连接状态!可能是您的电脑没有连入网络或网络配置错误."
Exit Function
Else
ConnectServer = True
lpNet.bIsConnect = True
End If
Else
ConnectServer = True
lpNet.bIsConnect = True
End If
End Function