Link to home
Start Free TrialLog in
Avatar of circler
circlerFlag for Lebanon

asked on

WNetUseConnection Error

Hey there,

I am using this function "WNetUseConnection" , it's working fine on many systems, but when I am using it on win2k3 R2 I am getting 1213 error which is "the network could not be reached"..
Here is the snippet of parameters I am passing to this function, I hope someone can point me out to fix this error..

p.s: rc is returning 1213, it returns 0 ERROR_SUCCESS on other systems
thanks
TCHAR szRemoteResource[_MAX_PATH];
   TCHAR  szAccessName[0x100];
   DWORD rc,dwResult,dwBuffSize=0x100;
_snprintf( szRemoteResource,sizeof(szRemoteResource), ("\\\\%s\\%s"), "192.168.16.16", "IPC$");   
   NETRESOURCE nr;
      nr.dwType = RESOURCETYPE_ANY;
      nr.lpLocalName = NULL;
      nr.lpRemoteName = (LPTSTR)&szRemoteResource;
      nr.lpProvider = NULL;
rc=WNetUseConnection(GetForegroundWindow (),&nr, "",
		                                           "", CONNECT_INTERACTIVE,
		  szAccessName,&dwBuffSize,&dwResult);

Open in new window

Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

>> I am getting 1213 error which is "the network could not be reached"
According to the MSDN 1213 is...

ERROR_INVALID_SERVICENAME
1213 (0x4BD)
The format of the specified service name is invalid.
http://msdn.microsoft.com/en-us/library/ms681383.aspx

Have you tried calleding WNetGetLastError()?

The WNetGetLastError function retrieves the most recent extended error code set by a WNet function. The network provider reported this error code; it will not generally be one of the errors included in the SDK header file WinError.h.
http://msdn.microsoft.com/en-us/library/aa385459.aspx

What happens if you try to manually access this resource from the machine using "net use"?
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true
Avatar of circler

ASKER

I rechecked, the error was 1231 which is ERROR_NETWORK_NOTFOUND , I will use WNetGetLastError() and update this post..
thanks evilrix
Avatar of circler

ASKER

I rechecked using WNetGetLastError and also got this error:
ERROR_NETWORK_UNREACHABLE       The remote network is not reachable by the transport.        1231

Can anyone help ?
Thanks
>> I rechecked, the error was 1231 which is ERROR_NETWORK_NOTFOUND
Oops, I transposed the 1 and the 3 :) My bad -- doh! <--- slaps himself *hard*

Let me repost just to clear up the confusion I might have created

http://msdn.microsoft.com/en-us/library/ms681383.aspx
ERROR_NETWORK_UNREACHABLE
1231 (0x4CF)
The network location cannot be reached

>> Can anyone help ?
Did you try what I suggested above?

What happens if you try to manually access this resource from the machine using "net use"?
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true

Also, have you tried to ping the end-point from that machine to see if it can actually see it?
Avatar of circler

ASKER

C:\Documents and Settings\Administrator>net use \\192.168.16.16\$IPC
System error 1231 has occurred.

The network location cannot be reached. For information about network troublesho
oting, see Windows Help.
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of circler

ASKER

yeah, I agree, since the code works on different platforms but do you think it's possible to fix that problem ?
>> but do you think it's possible to fix that problem ?
From a code point if view, there is nothing to fix. From a windows networking point of view that is a new question that needs to be asked in a windows networking zone.
The asker agreed with my diagnosis {http:#24562532} here {http:#24562595} and since it wasn't a coding issue there was nothing else I could do to assist.