Post by Michael J. Leaver
I'm banging my head against the wall trying to get WNetAddConnection2 to
work. At the moment, every time I call it I'm getting ERROR_BAD_NETPATH
I'm not using a domain, and both computers are Windows XP SP1. I can
access the shares on the other computer no problem using Explorer or
even from the DOS prompt.
The remote name is passed in the normal format of
\\MACHINENAME\SHARENAME\ and I've tried both MACHINENAME\USERNAME and
USERNAME for the username. I've also tried passing nil for the username
and password. I've tried everything but it just refuses to work.
Any help appreciated.
For XP Home share you typically can only access it as the guest account.
Make sure the guest account is active and pass NULL for username and the
guest password in the password field.
memset(&nr, 0, sizeof(NETRESOURCE));
sprintf(path, "\\\\%s\\%s",server_name, server_path);
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = NULL;
nr.lpRemoteName = path;
nr.lpProvider = NULL;
if (*username == 0)
if (*password == 0)
error = WNetAddConnection2(&nr, NULL, NULL, 0);
error = WNetAddConnection2(&nr, password, NULL, 0);
error = WNetAddConnection2(&nr, password, username, 0);