请教高手:想读取远程电脑上的一个文本文件,查了相关网上资料使用WNetAddConnection2方法进行网络映射,代码如下:
    Dim NR As NETRESOURCE
    Dim MyErr As Long    NR.dwScope = RESOURCE_GLOBALNET
    NR.dwType = RESOURCETYPE_DISK
    NR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
    NR.dwUsage = RESOURCEUSAGE_CONNECTABLE
    NR.lpLocalName = "d;"
    NR.lpRemoteName = "\\10.86.35.28\D$"
    
    MyErr = WNetAddConnection2(NR, "123456", "admin", CONNECT_UPDATE_PROFILE)    If MyErr = NO_ERROR Then        MsgBox "映射成功!", vbInformation, "信息提示"    Else        MsgBox "出现错误:" & Err.Description & " -映射失败!", vbExclamation, "信息提示"    End If已经将对方文件夹设为共享了,运行后为什么访问不了?
是不是lpLocalName和lpRemoteName等参数有问题??谢谢~~~

解决方案 »

  1.   

    CONNECT_UPDATE_PROFILE等于多少咋没说?
      

  2.   

    Public Const CONNECT_UPDATE_PROFILE = &H1
    表示创建的是永久性连接
      

  3.   

    运行后WNetAddConnection2的返回值为1200
      

  4.   

    Private Const ERROR_BAD_DEVICE = 1200&
    The value specified by lpLocalName is invalid.
    指定的lpLocalName 无效
      

  5.   

    NR.lpLocalName = "d;"
      

  6.   

    lpLocalName Points to a null-terminated string that specifies the name of a local device to be redirected, such as "F:" or "LPT1". The string is treated in a case-insensitive manner. If the string is empty or lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device. 你该用冒号
    并且没有用过这个盘符才可以,这是映射后的盘符
      

  7.   

    NR.lpLocalName = "d:"
    把D改成其他的也一样
      

  8.   

    返回值是5
    这个返回值的帮助在MSDN里?
      

  9.   

    返回值是5表示对方拒绝
    这个返回值的帮助不在MSDN里
      

  10.   

    为什么会拒绝呢?
    我run的时候都能看到对方的文件,需要更改什么设置吗?