WNetAddConnection2 returns 1219

R3D3vil picture R3D3vil · Jun 1, 2011 · Viewed 15.3k times · Source

I am using WNetAddConnection2 and WNetCancelConnection2 to map or unmap drives.

What i am trying to do is as follows:
I mapped a folder(eg:Folder1) on server(eg:myserver). so the path is \\myserver\Folder1 and i map it to drive X.
Now i want to map another folder(eg:Folder2) on same myserver to drive Y programmatically.

When i call the method WNetAddConnection2 after mapping one folder it returns 1219 instead of 0 and i get the error:Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

I am confused because i can map Folder2 on the same server by doing a right click on MyComputer and choosing map network drive..., but not programmatically.

Am i missing something or do i need to use the NETRESOURCE structure differently or anyhting else?

Thanks

Answer

ribram picture ribram · Jun 2, 2011

Are you mapping X: programmatically as well? If so are you using the same username and password specification in the calls to WNetAddConnection2()? The 1219 error would indicate that you are attempting to map multiple drives to the same server using different authentications. I have successfully made multiple WNetAddConnection2() to multiple shares on the same server when using the same user/pass combination.