We help IT Professionals succeed at work.

Passing credentials through NET USE without hard coding the password?

1,139 Views
Last Modified: 2017-05-01
What I am trying to do is setup a scheduled job that copies files from a server not joined to the corporate domain to a server that is in the domain.
I am using robocopy.

It would be very easy to do:

net use \\IP\c$ /user:myuser mypassword

robocopy C:\mydir "\\IP\c$\copydir" /copyall

Open in new window


But I do not want to leave the password to this account hardcoded in a .bat file. Is there a more secure way I can store and pass credentials to the domain computer?
Comment
Watch Question

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Kevin StanushApplication Developer

Commented:
The passthru authentication suggested by Qlemo will work, but you might also try the Credential Manager in Control Panel > Users.  It might let you securely store a password that Net Use would use.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
The Credential Manager needs to be called as the task user for that to work, of course.
Kevin StanushApplication Developer

Commented:
I assume you don't want to use a persistent connection (mapped drive) for security reasons?  Also, you said that you were using this as a scheduled job/task, so what if you set the credentials in the task itself.  The command to run robocopy could be reduced to just one command, since the process would already have the right credentials.
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Kevin, because of
from a server not joined to the corporate domain to a server that is in the domain
it isn't that simple ;-).
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
If RoboCopy is your only or last command, the result code is from RoboCopy, see https://ss64.com/nt/robocopy-exit.html.
0x3 means 0x1 (new files on source) and 0x2 (extra files on destination not being on source).
In a batch file you can override that by running exit /b 0 as very last statement. Then your task will result in 0 if the batch ran.

Author

Commented:
Thanks again!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.