Nastya Gorobets
Nastya Gorobets

Reputation: 197

WNetAddConnection2 returns error 1200

I have shared network folder on my disk C:\folder.

When I use WNetAddConnection2 I get error 1200. My code is:

DWORD dwResult;
NETRESOURCE nr;
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = (LPWSTR)"folder";
nr.lpRemoteName = (LPWSTR)"\\\\ASYA\\folder";
nr.lpProvider = NULL;
dwResult = WNetAddConnection2(&nr,NULL,(LPCWSTR) "Nastya",CONNECT_UPDATE_PROFILE); 

if (dwResult == NO_ERROR)
    wprintf(L"Connection added to %s\n", nr.lpRemoteName);
else
    wprintf(L"WNetAddConnection2 failed with error: %u\n", dwResult);

What is my mistake? How can I solve this problem?

Upvotes: 0

Views: 2966

Answers (1)

maykonmeier
maykonmeier

Reputation: 26

Hei,

Error 1200 means that your LocalName(ShareName) is invalid as explained here: microsoft

ERROR_BAD_DEVICE 1200 (0x4B0) The specified device name is invalid.

Probably you should name your LocalName as "Z:" or "X:".

About your error code 85 it means that

ERROR_ALREADY_ASSIGNED 85 (0x55) The local device name is already in use.

It's almost sure that your unit named C: is already been used by your Windows.

You can see all errors code means into Microsoft web site on link above.

Upvotes: 1

Related Questions