Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WNetAddConnection2 returns 1219

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

like image 942
R3D3vil Avatar asked Jun 01 '11 20:06

R3D3vil


2 Answers

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.

like image 166
ribram Avatar answered Oct 21 '22 12:10

ribram


In case anyone else has this issue, I happened to have the file share in question open in an Explorer window without realizing it. I closed the window and then the code worked fine.

like image 24
Jim Avatar answered Oct 21 '22 11:10

Jim