Copy Files Between Untrusted Domains Programmatically

Normally on a Windows machine when you attempt to access a share in a different domain you are prompted for credentials.  However, there are no copy utilities (copy, xcopy, robocopy, etc) that pass credentials in the command line.  Also, as it is an untrusted domain, you simply can’t do a RunAs (need to manually type in a password for that anyways).

The answer was so obvious, I can’t believe it didn’t come to me right away.  However, net use, the simplest of commands, is your friend again.  Using the following command you can initiate the connection and then copy between the machines as much as you like via normal UNC path.

net use [server][path] [password] /user:[username]

copy [server][path][more path]

net use [server][path] /delete /y

By using the following syntax there is no mapped drive.  There is simply a stored connection with the associated credentials for the life of the profile or until the delete command is run. 

Comments

One response to “Copy Files Between Untrusted Domains Programmatically”

  1. vaibhav Avatar
    vaibhav

    i want to copy file from source to destination machine how is possible?????