Search code examples
batch-filecopywindows-server-2008-r2virtual-directory

How to run a batch on another server to copy a file to not shared directory


Plz help..

I am trying to run a batch on another server to copy a file to not shared directory (not UNC):

  • there are two servers and two batch files: serv01 serv02 & bat1 bat2
  • bat1 runs from serv01 and bat2 located on serv02 is called by bat1 from serv01
  • bat2 is shared on serv02 so serv01 can see it
  • I am trying to copy a file from serv01 to serv02. Copy destination path is not shared, but the bat2 is local on serv02 like, so the "double click" run will do the job.

bat1:

call "\\serv2\folder\bat2.bat"

bat2:

SET path01="\\serv01\deployment\serv02"

SET path02="d:\application\ui"

copy "%path01%\web.config" "%path02%\web.config"

I have tried %~dp0 but this only uses the shared folder directory and can only copy to that folder(not desired location)

I tried PUSHD but this also creates a local virtual directory so in this case is path01 and this only, where I am trying to copy a file to local path02 (serv02)

I know there is always a problem with reading UNC`s and I couldnt find an answer to this on stack. Is there a way to run bat02 as local but still pull path01? As a "double click" run on the bat2 is working fine and does the job.

Many thanks!


Solution

  • If you are an admin then everything is shared. The admin shares C$, D$, ..., N$ are admin hidden shares.

    copy  "\\serv01\C$\folder\file.ext" "\\serv02\C$\folder\file.ext"
    

    There are also Print$ and Admin$ shares. Type net share to see list.

    To run a file remotely

    wmic /node:serv02 process call create "cmd /c somefile.bat"