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

Posted on 2011-04-20
Last Modified: 2012-05-11
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.
Question by:endrec
    LVL 13

    Expert Comment

    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.
    LVL 8

    Accepted Solution

    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..

    Author Comment

    I believe inserting the password in plain text is permissible in this case.
    LVL 8

    Expert Comment

    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
    LVL 32

    Expert Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now