Link to home
Start Free TrialLog in
Avatar of SeeDk
SeeDk

asked on

Passing credentials through NET USE without hard coding the password?

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?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
The Credential Manager needs to be called as the task user for that to work, of course.
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.
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 ;-).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of SeeDk
SeeDk

ASKER

Thanks again!