R3D3vil
R3D3vil

Reputation: 681

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

Upvotes: 6

Views: 16875

Answers (3)

RSN
RSN

Reputation: 1

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;
      }

////

Upvotes: 0

Jim
Jim

Reputation: 3508

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.

Upvotes: 5

ribram
ribram

Reputation: 2460

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.

Upvotes: 5

Related Questions