我在一台Linux上在设置一共享文件夹,通过win7去访问该共享目录,使用WNetAddConnection2去建立连接,把该共享目录映射到本地磁盘,但是老是返回连接不成功的错误信息,如果我使用运行直接访问该共享目录,然后再用WNetAddConnection2去连接就OK了,请问这是个什么情况?
如何让WNetAddConnection2随时可以连接成功?
返回值是1219
Dim NetR As New NETRESOURCE
Dim ErrInfo As Long
NetR.dwScope = RESOURCE_CONNECTED
NetR.dwType = RESOURCETYPE_ANY
NetR.dwDisplayType = RESOURCETYPE_ANY
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpRemoteName = NetPath
ErrInfo = WNetAddConnection2(NetR, Passowrd, UserAcc, 0)
If ErrInfo = NO_ERROR Then
DLLErr = ""
Else
If ErrInfo.ToString = "1219" Then
'如果出现1219错误,选断开再连接
WNetCancelConnection2(NetPath, 0, True) ErrInfo = WNetAddConnection2(NetR, Passowrd, UserAcc, 0)
If ErrInfo = NO_ERROR Then
DLLErr = ""
Else
DLLErr = ErrInfo.ToString
End If
Else
DLLErr = ErrInfo.ToString
End If
End If我用以上方法搞定。
Dim ErrInfo As Long
NetR.dwScope = RESOURCE_CONNECTED
NetR.dwType = RESOURCETYPE_ANY
NetR.dwDisplayType = RESOURCETYPE_ANY
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpRemoteName = NetPath
ErrInfo = WNetAddConnection2(NetR, Passowrd, UserAcc, 0)
If ErrInfo = NO_ERROR Then
DLLErr = ""
Else
If ErrInfo.ToString = "1219" Then
'如果出现1219错误,选断开再连接
WNetCancelConnection2(NetPath, 0, True) ErrInfo = WNetAddConnection2(NetR, Passowrd, UserAcc, 0)
If ErrInfo = NO_ERROR Then
DLLErr = ""
Else
DLLErr = ErrInfo.ToString
End If
Else
DLLErr = ErrInfo.ToString
End If
End If我用以上方法搞定。
温馨提示:答案为网友推荐,仅供参考