How to create a .bat file that copies a file from one server to another under a particular user account?

We have a need to copy a files from one location on a server to another location on a different server, however we need to impersonate or use the credentials of a particular service account.  Is it possible to get a .bat file to copy a file using the credentials of a particular user, not neccessarily the user the executed the .bat file?

Example:  We need File A to be copied from Server A Location A to Server B Location B.  The .bat file is run by James, but the file copy needs to occur under Joe's account.
Who is Participating?
you can do that..but the RUNAS user's password will has to be inserted in the batch as plain text. Will that be OK ?

Set ws = CreateObject("WScript.Shell")
ws.Run "runas.exe /user:joe cmd.exe /c batch.bat" 
wscript.sleep 2000
ws.SendKeys "password"
ws.SendKeys "{ENTER}"

Open in new window

run this VBS from the same folder where the batch file is present..
Best way to do this would be to create a normal .bat account and then use Scheduled Tasks under Acessories -> system tools.

These tasks will let you run a .bat file from a specific user at specific interval.

I would avoid putting this info in the .bat file because that compromises that user's password.
endrecAuthor Commented:
I believe inserting the password in plain text is permissible in this case.
alright...try this...Create a text file in the same folder where you batch file is and save as runa.vbs extension.
copy the code from above post and paste in that text it.

Now run the vbs by double clicking on it or by running cscript filename.vbs

let us know if issues
i wouldn't let the user's call batch files where the credentials of an account can be seen in plain text. even if you trust your users there can be malware which spies into those files.

i would let the user copy the file(s) to a share on the own computer (James). then at the destination account (Joe) there could be a local job in the task list (at) which periodically copies files from shares to that account.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.