Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WNetAddConnection2 returning ERROR_BAD_NETPATH

3,337 views
Skip to first unread message

Michael J. Leaver

unread,
Jan 12, 2004, 3:49:04 AM1/12/04
to
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]

unread,
Jan 13, 2004, 3:35:58 PM1/13/04
to
"Michael J. Leaver" <sp...@mjleaver.com> wrote

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

unread,
Jan 13, 2004, 10:17:57 PM1/13/04
to
Chris P. [MVP] wrote:
> "Michael J. Leaver" <sp...@mjleaver.com> wrote
> 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);
>
>

My code is identical, but I'm still getting the same error :( Also, I'm
using XP Pro.

Thanks anyway.

Ken Wickes [MSFT]

unread,
Jan 14, 2004, 2:29:45 PM1/14/04
to

"Michael J. Leaver" <sp...@mjleaver.com> wrote in message
news:evRV6zk2...@tk2msftngp13.phx.gbl...

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

unread,
Jan 14, 2004, 10:19:12 PM1/14/04
to
Ken Wickes [MSFT] wrote:
>
> 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

unread,
Feb 15, 2012, 9:04:49 AM2/15/12
to
Ken Wickes [MSFT] wrote on 01/14/2004 14:29 ET :
> "Michael J. Leaver" wrote in message
> news:
>> Chris P. [MVP] wrote:
>> > "Michael J. Leaver" wrote
>> > 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);
>> >
>> >
>>
>> 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.
>
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 !!!
0 new messages