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:user_of_DirA@domain.net
net use \\pc1.domain.net\Shared\DirB pwd2 /user:user_of_DirB@domain.net
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?