BUG: WNetUseConnection Returns ERROR_ALREADY_ASSIGNED on Windows 2000

Article translations Article translations
Article ID: 257298 - View products that this article applies to.
This article was previously published under Q257298
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SYMPTOMS

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.

CAUSE

The function is failing to choose the correct local device for redirection.

RESOLUTION

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 the Microsoft Knowledge Base:
260910 How to Obtain the Latest Windows 2000 Service Pack

STATUS

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.

MORE INFORMATION

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;
 
};
				

Properties

Article ID: 257298 - Last Review: October 20, 2013 - Revision: 3.2
APPLIES TO
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
Keywords: 
kbnosurvey kbarchive kbdswnet2003swept kbapi kbbug kbfix kbnetwork kbwin2000sp1fix kbwnet KB257298

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com