Search code examples
windowsvbscriptbatch-filepsexec

Batch file - Remote Copy and Execute issue


I have a batch file that part of it copies a folder and its content to a local directory and then continues through the batch process which then tries to execute the contents of the folder . locally run it works on all wintel os and copies the files from \networkshare\folder*.* to %systemdrive%\temp\ .

I have attempted to use e.g psexec @serverlist.txt -c batfile.bat -s -f -d to copy the file and then execute it remotely how ever the issue is that this will not copy the files when run remotely . I think its a authentication issues after you a have remotely executed the batch file the remote system will not allow me to access/authenticate the networkshare

i have tried xcopy , copy , robocopy .


Solution

  • AFAIK you can only authenticate against the next hop using implicit credentials. Connection attempts from the first hop to a second hop will fail, even if your user has the required permisssions. See e.g. here for an explanation.

    Try this:

    psexec @serverlist.txt -u %USERDOMAIN%\%USERNAME% -d -c batfile.bat
    

    Use explicit credentials so you're authenticated against the remote host. With that the second hop will be the next hop for your authenticated session. Don't run the script as LOCAL SYSTEM (-s), because that account is restricted to local resources.