question

MarkRockman-5419 avatar image
0 Votes"
MarkRockman-5419 asked LeilaKong-MSFT commented

WNetCancelConnection2 and WNetAddConnection2: Cancel gets code 2250, Add gets Success!

        driveLetter = driveLetter.ToUpper();
         if (driveLetter.Length == 1)
             driveLetter = driveLetter + ":";
         msg1 = "Disconnect drive letter (" + driveLetter + ") if connected or not.";
         uint dwResult = WNetCancelConnection2(driveLetter, CONNECT_UPDATE_PROFILE, true);    // same as NET USE <drive-letter>:   /DELETE
         obj.WriteEntry("WNetCancelConnection2 status code:");
         DisplayErrorMessage(dwResult, obj);
         if (dwResult != 0)
         {
             obj.WriteEntry("Getting rid of pre-existing mapping of network drive produced an error.");
             obj.WriteEntry("Let's see if establishing a working mapping also produces an error.");
         }
         NETRESOURCE networkResource = new NETRESOURCE();
         networkResource.dwType = RESOURCETYPE_DISK;
         networkResource.lpLocalName = driveLetter;
         networkResource.lpRemoteName = path;
         networkResource.lpProvider = null;
         dwResult = WNetAddConnection2(ref networkResource, passwd, userid, 0);  // same as NET USE <drive-letter>:   \\<remote-computer>\<directory-name>
         obj.WriteEntry("WNetAddConnection2 status code:");
         DisplayErrorMessage(dwResult, obj);
         if (dwResult != 0)
             return false;   // damn thing failed
         return true;

Seems to me that it would be good design to avoid issuing error 2250 on the Cancel when the Add will work just fine.

windows-10-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeilaKong-MSFT avatar image
0 Votes"
LeilaKong-MSFT answered

Hello @MarkRockman-5419 ,

Thanks for your query. Please check the following post for reference:

https://stackoverflow.com/questions/9085586/wnetaddconnection2-and-error-1219-automatically-disconnect
https://social.msdn.microsoft.com/Forums/vstudio/en-US/6e9a6aab-2b6a-4528-a5b5-26b0c7cd22f4/wnetcancelconnection2-does-not-close-a-connection?forum=vcgeneral


Best regards,
Leila


If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkRockman-5419 avatar image
0 Votes"
MarkRockman-5419 answered LeilaKong-MSFT commented

It appears that the issue that I raised has been an issue for years without resolution. It has been suggested that the CANCEL request be modified to request that, instead of issuing an error code (2250 in this case), Windows should do whatever it does and issue the NO_ERROR status. Actually I don't care that I get a different status than NO_ERROR as long as I am able to map the relevant drive letter to the remote network drive. Many times, after a reboot, the mappings persist but cannot be used. I suppose this is a "fix" for a security issue. I haven't found this behavior documented. Nor have I found it documented that mapping a drive letter in privileged mode is different than mapping a drive letter not in privileged mode. Situation normal.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @MarkRockman-5419 ,

Thanks for your response. We sincerely recommend that you open a case to Microsoft for further professional help.
https://support.microsoft.com/en-us/help/4341255/support-for-busines

0 Votes 0 ·