Microsoft KB Archive/257298

From BetaArchive Wiki

BUG: WNetUseConnection Returns ERROR_ALREADY_ASSIGNED on Windows 2000

Q257298



The information in this article applies to:


  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Professional





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, please see the following article in the Microsoft Knowledge Base:

Q260910 How to Obtain the Latest Windows 2000 Service Pack



STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

Microsoft has confirmed this to be 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;
 
}; 

Additional query words:

Keywords : kbnetwork kbAPI kbOSWin2000 kbSDKPlatform kbSDKWin32 kbWNet _IK kbGrpDSNet kbWin2000PreSP1Fix kbWin2000sp1Fix
Issue type : kbbug
Technology : kbwin2000AdvServ kbwin2000AdvServSearch kbwin2000Serv kbwin2000ServSearch kbwin2000Search kbwin2000ProSearch kbwin2000Pro kbWinAdvServSearch


Last Reviewed: November 17, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.