Discussion:
WNetAddConnection2 returning ERROR_BAD_NETPATH
(too old to reply)
Michael J. Leaver
2004-01-12 08:49:04 UTC
Permalink
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
(53) returned.

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.
Chris P. [MVP]
2004-01-13 20:35:58 UTC
Permalink
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
(53) returned.
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.

char path[80];
UINT error=0;
NETRESOURCE nr;

memset(&nr, 0, sizeof(NETRESOURCE));

if (*server_path)
sprintf(path, "\\\\%s\\%s",server_name, server_path);
else
sprintf(path, "\\\\%s",server_name);

nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = NULL;
nr.lpRemoteName = path;
nr.lpProvider = NULL;

//retryconnect:
if (*username == 0)
{
if (*password == 0)
error = WNetAddConnection2(&nr, NULL, NULL, 0);
else
error = WNetAddConnection2(&nr, password, NULL, 0);
}
else
error = WNetAddConnection2(&nr, password, username, 0);
Michael J. Leaver
2004-01-14 03:17:57 UTC
Permalink
Post by Chris P. [MVP]
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.
char path[80];
UINT error=0;
NETRESOURCE nr;
memset(&nr, 0, sizeof(NETRESOURCE));
if (*server_path)
sprintf(path, "\\\\%s\\%s",server_name, server_path);
else
sprintf(path, "\\\\%s",server_name);
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);
else
error = WNetAddConnection2(&nr, password, NULL, 0);
}
else
error = WNetAddConnection2(&nr, password, username, 0);
My code is identical, but I'm still getting the same error :( Also, I'm
using XP Pro.

Thanks anyway.
Ken Wickes [MSFT]
2004-01-14 19:29:45 UTC
Permalink
Post by Michael J. Leaver
Post by Chris P. [MVP]
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.
char path[80];
UINT error=0;
NETRESOURCE nr;
memset(&nr, 0, sizeof(NETRESOURCE));
if (*server_path)
sprintf(path, "\\\\%s\\%s",server_name, server_path);
else
sprintf(path, "\\\\%s",server_name);
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);
else
error = WNetAddConnection2(&nr, password, NULL, 0);
}
else
error = WNetAddConnection2(&nr, password, username, 0);
My code is identical, but I'm still getting the same error :( Also, I'm
using XP Pro.
Thanks anyway.
Can you map the share with "net use"?

Have you tried it without the trailing backslash?
--
Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.
Michael J. Leaver
2004-01-15 03:19:12 UTC
Permalink
Post by Ken Wickes [MSFT]
Can you map the share with "net use"?
Have you tried it without the trailing backslash?
Thanks Ken! Seems it works without the trailing backslash...very strange
because I'm positive I'd already tried that several times...
abhay
2012-02-15 14:04:49 UTC
Permalink
Ken Wickes [MSFT] wrote on 01/14/2004 14:29 ET
"Michael J. Leaver" wrote in messag
news
Post by Michael J. Leaver
"Michael J. Leaver" wrot
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 th
guest password in the password field
char path[80]
UINT error=0
NETRESOURCE nr
memset(&nr, 0, sizeof(NETRESOURCE))
if (*server_path
sprintf(path, "\%s%s",server_name, server_path)
els
sprintf(path, "\%s",server_name)
nr.dwType = RESOURCETYPE_DISK
nr.lpLocalName = NULL
nr.lpRemoteName = path
nr.lpProvider = NULL
//retryconnect
if (*username == 0
if (*password == 0
error = WNetAddConnection2(&nr, NULL, NULL, 0)
els
error = WNetAddConnection2(&nr, password, NULL, 0)
els
error = WNetAddConnection2(&nr, password, username, 0)
My code is identical, but I'm still getting the same error :( Also, I'
using XP Pro
Thanks anyway
Can you map the share with "net use"
Have you tried it without the trailing backslash
Ken Wickes [MSFT
This posting is provided "AS IS" with no warranties, and confers n
rights
Thanks a lot Ken !!

I was looking for this issue since last 2 days!!! The trick was as you said
use remote path without trailing slash !!

Highly Appreciated !!!

Loading...