Connect to admin$ share

249 views Asked by At

I am going to conenct to share folder (admin$) on remote computer in my network. This is code which I wrote in order to do it.

    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));

I wrote windows service and run my code from it.

The problem is that function WNetAddConnection2 returns error:

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.

I am definitely sure is that:

  1. Login/password are correct.
  2. Windows firewall was turned off on my and remote computer.
  3. Network path is correct.

My question is what do I need to do in order to connect to remote computer properly and where is my mistake?

Thanks.

0

There are 0 answers