我打算在网络中的远程计算机上共享文件夹(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.
我绝对肯定是:
我的问题是我需要做些什么才能正确连接到远程计算机以及我的错误在哪里?
感谢。