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?
Windows Server 2008* RobocopyWindows BatchWindows OS

Avatar of undefined
Last Comment
SeeDk
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Kevin Stanush
Kevin Stanush
Flag of United States of America image

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.
Avatar of Qlemo
Qlemo
Flag of Germany image

The Credential Manager needs to be called as the task user for that to work, of course.
Avatar of Kevin Stanush
Kevin Stanush
Flag of United States of America image

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.
Avatar of Qlemo
Qlemo
Flag of Germany image

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
Avatar of SeeDk
SeeDk

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Qlemo
Qlemo
Flag of Germany image

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!
Windows OS
Windows OS

This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo