WNetAddConnection2 returns 1219
Asked Answered
P

3

6

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

Parol answered 1/6, 2011 at 20:32 Comment(0)
A
5

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.

Austen answered 2/6, 2011 at 20:43 Comment(3)
Yes i found that out later that i can map different folders on the same server with same credentials by changing the flag value for the wnetaddconnection2 method... but now i am trying to map 2 different folders on the same server with 2 different user/pass credentials and that doesnt work programmatically or otherwise..Parol
Windows doesn't really want to allow that, but there are different hacks using aliases or hostname vs. ip address etc. to try and achieve this. See here linkAusten
My code was hitting this error. I just caught the error, ignored it and all worked fine. Probably not a great idea but it worked for me.Isotope
E
5

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.

Eisk answered 20/9, 2016 at 17:42 Comment(0)
D
0

Very late reply but hope can help. My way of doing is to call the net delete command in C#.

////

string strParam = @"/c net use * /delete /Y";
string strOutput = MappedDriveResolver.DoProcess("cmd", strParam);

public static string DoProcess(string cmd, string argv)
  {
      Process p = new Process();
      p.StartInfo.UseShellExecute = false;
      p.StartInfo.RedirectStandardOutput = true;
      p.StartInfo.FileName = cmd;
      p.StartInfo.Arguments = argv;
      p.StartInfo.CreateNoWindow = true;
      p.Start();
      p.WaitForExit();
      string output = p.StandardOutput.ReadToEnd();
      p.Dispose();
      return output;
      }

////

Discophile answered 2/8, 2021 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.