2

I'm working on a code that could copy files between two arbitrary network file shares, i.e.:

copy files from  \\pc1.domain.net\Shared\DirA   // source shared folder
to               \\pc2.domain.net\Shared\DirB   // target shared folder

Internally, this works by first calling net use to establish an (anonymous) connection to a shared folder on a specific remote machine. In the above case, two connections will be established at the same time, then files will be read from source share and written to target share in chunks.

One concern I have here is a situation where both source and target shared folder are on the same remote machine - this can cause "multiple connections" error (1219). I.e. I want to copy files from \\pc1.domain.net\Shared\DirA to \\pc1.domain.net\Shared\DirB. The code is being executed from the same Windows account, and the file shares can have different access credentials and permissions. So what I'm trying to do is, from the same Windows account, execute something like:

net use \\pc1.domain.net\Shared\DirA   pwd1   /user:[email protected] 
net use \\pc1.domain.net\Shared\DirB   pwd2   /user:[email protected]

However, Windows by design seems to think these connections refer to the same resource because they are on the same machine, and sometimes it looks like error 1219 may happen in the above case:

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.

This means that I may run into a situation where it's impossible to have two connections established like above - at least testing this by hand via cmd results in error 1219. I'm pretty much forced to do a net use /delete, but this prevents me from doing what I want (not to mention that user may have other unrelated connections established to the same machine and I must kill them for him - ugly). It makes NO sense to me why Windows have this limitation (I'm using 7 and Server 2008 R2).

Is there an easy solution where I can have two connections to two shared folders on the same remote machine established from the same Windows account without running into error 1219?

2
  • Interesting. Does it in Powershell too, always assumed that it was just a DOS thing.
    – Patrick
    Jan 10, 2014 at 11:06
  • @Patrick yes, it's an internal Windows problem - it persists even if you implement everything using native Win32 functions intended for establishing connections.
    – w128
    Jan 10, 2014 at 12:26

1 Answer 1

2

Using FQDN, hostname and IP address, you can have three connections with different credentials to the same server.

E.g.:

net use \\pc1.domain.net\Shared\DirA /user:[email protected] pwd1
net use \\pc1\Shared\DirB /user:[email protected] pwd2
net use \\1.1.1.1\Shared\DirC /user:[email protected] pwd3

(I've always entered password as the last parameter)

2
  • I have thought of using an IP myself, but I should have noted that the machine location may be an IP in the first place - meaning all I've got to work with is an input location like "\\1.1.1.1\Shared". Still, it seems to be the only real way to do it...
    – w128
    Jan 10, 2014 at 12:03
  • But the computer will still have a hostname. If you can't resolve that, you can add it to your hosts file. Just make sure the name matches, or you will probably get errors. See support.microsoft.com/kb/281308
    – abstrask
    Jan 10, 2014 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .