tags:

views:

148

answers:

1

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!

A: 

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.

Hans Passant