BUG: WNetUseConnection Returns ERROR_ALREADY_ASSIGNED on Windows 2000

This article was previously published under Q257298
This article has been archived. It is offered "as is" and will no longer be updated.
On Windows 2000, a call to WNetUseConnection() with the lpLocalName member of NETRESOURCE structure set to "NULL" and dwFlags set to "CONNECT_REDIRECT" returns error 85, "ERROR_ALREADY_ASSIGNED". This also affects ShellExecuteEx() when used with the SEE_MASK_CONNECTNETDRV flag.
The function is failing to choose the correct local device for redirection.
To resolve this problem, obtain the latest service pack for Windows 2000. For additional information, click the following article number to view the article in theMicrosoft Knowledge Base:
260910 How to Obtain the Latest Windows 2000 Service Pack
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was first corrected in Windows 2000 Service Pack 1.
According to the WNetUseConnection() documentation on the MSDN, if the CONNECT_REDIRECT value is set in the dwFlags parameter, and if lpLocalName is "NULL", the function should choose a local device to redirect and should return the name of the device in the lpAccessName parameter. But on Windows 2000, WNetUseConnection() fails with the error, "ERROR_ALREADY_ASSIGNED".

Steps to Reproduce Behavior

Use the following code snippet to reproduce the problem:
 #include <Windows.h> #include <stdio.h> #include <winnetwk.h>int main(void){   DWORD       nRet;    NETRESOURCE nr;   LPTSTR      buff;   DWORD       buffsize = 256;   nr.lpLocalName  = NULL;   nr.lpRemoteName = (LPSTR) GlobalAlloc(GPTR, 256);   buff	           = (LPSTR) GlobalAlloc(GPTR, 256);	   nr.dwType = RESOURCETYPE_DISK;   lstrcpy(nr.lpRemoteName, "\\\\mycomputer\\testshare");   nr.lpProvider = NULL;   nRet = WNetUseConnection(  NULL,                              &nr,  //connection details                               NULL,                              NULL,                               CONNECT_REDIRECT,                                buff,                              &buffsize,                              0                               );  if (nRet != 0)      printf("Function returned error %d \n", nRet);  else {     printf("Function returned Successfully \n");     printf("AccessName %s \n", buff); }  return 0; };				

Article ID: 257298 - Last Review: 10/20/2013 18:18:25 - Revision: 3.2

Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, Microsoft Windows 2000 Professional Edition

  • kbnosurvey kbarchive kbdswnet2003swept kbapi kbbug kbfix kbnetwork kbwin2000sp1fix kbwnet KB257298