Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error 1202 - ERROR_DEVICE_ALREADY_REMEMBERED in WNetAddConnection2A

Tags:

.net

winapi

I used the function - WNetAddConnection2A(n, UserName, Password, dwFlags) to programmatically map a drive and read the drive info out, and then used WNetCancelConnection2A(DriveLetter, dwFlags, ForceDisconnect) to unmap the drive. The first map and unmap were fine. But the next map will bring me the error 1202 - ERROR_DEVICE_ALREADY_REMEMBERED when the same driver letter is used.

I set dwFlags = 0. It works in my development machine but fails in server. How to eliminate the error 1202?

Thanks!

like image 784
Don Avatar asked Nov 23 '25 00:11

Don


1 Answers

Don't include CONNECT_UPDATE_PROFILE. It probably failed on the server because something else had already mapped the drive and left the "Reconnect at logon" option turned on. It is on by default. Fix by disconnecting the drive in My Computer.

Or use WNetCancelConnection2 if you get the error. Now you do want to use CONNECT_UPDATE_PROFILE so it is permanently forgotten. Watch out for fForce, it is fairly unhealthy.

Using the UNC name instead of mapping drives is the best all-around strategy. Sounds like that's something you should use if you just temporarily map a drive.

like image 114
Hans Passant Avatar answered Nov 25 '25 19:11

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!