1

我将在我的网络中的远程计算机上共享文件夹 (admin$)。这是我为了做到这一点而编写的代码。

    std::wstring remoteRc(L"\\\\WIN7-PRO-X86\\admin$");
    NETRESOURCE nr;
    ::ZeroMemory(&nr, sizeof(NETRESOURCE));
    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = nullptr;
    nr.lpRemoteName = &remoteRc[0];
    nr.lpProvider = nullptr;

    DWORD res;
    res = ::WNetAddConnection2(&nr, L"admin", L"WIN7-PRO-X86\\Admin", CONNECT_TEMPORARY);
    if (res != NO_ERROR)
    {
        logger_.information("Unable to connect to resource, code: %lu", res);
        CHECK_OS_ERROR_CODE(res);
    }

    logger_.information("Connection has been added to the remote resource: %s", utils::cw2a(remoteRc));

我编写了 Windows 服务并从中运行我的代码。

问题是函数WNetAddConnection2返回错误:

2017-09-15 13:32:31.360 [Information] Unable to connect to resource, code: 5
2017-09-15 13:32:31.491 [Information] Error occurred: Access is denied.

我可以肯定的是:

  1. 登录名/密码正确。
  2. 我和远程计算机上的 Windows 防火墙已关闭。
  3. 网络路径正确。

我的问题是我需要做什么才能正确连接到远程计算机,我的错误在哪里?

谢谢。

4

0 回答 0