1

WinXP, Win7

FIRST.BAT Calls SECOND.BAT. Can SECOND.BAT safely replace FIRST.BAT?

FIRST.BAT:

@echo Hi, I need to be placed.
CALL SECOND.BAT

SECOND.BAT:

@echo Time to replace FIRST.BAT
copy /y NEWFIRST.BAT FIRST.BAT

Thanks!

  • 1
    Don't use `CALL second.bat`. Just use `SECOND.BAT`. This way control is passed to second.bat and first.bat exits. – Squashman Mar 08 '17 at 21:06
  • Ah, I wish I could... FIRST.BAT is already deployed on local machines.It Calls a common script on a networked location. I want to replace FIRST.BAT from that common SECOND.BAT script. Good idea, though... – Frank Ramage Mar 08 '17 at 21:10
  • 1
    Provided that the contents of the new `first.bat` are identical to the old contents up to and including the `call` command, yes, this will work. (Technically even that isn't necessary, the contents don't need to be the same, the offset in the file just has to be correct.) – Harry Johnston Mar 08 '17 at 21:19
  • So push a new FIRST.bat to the computers using a GPO or put something in their logon script to redeploy it again. – Squashman Mar 08 '17 at 21:20
  • @Harry I was afraid of that... was seeing if still applied in this instance. thx – Frank Ramage Mar 08 '17 at 21:25
  • @Squashman FIRST.BAT is the only startup control I have common to all these devices, so I'm searching for a method to replace FIRST.BAT with the limitations I have. Was hoping the fact that SECOND.BAt is CALLed by FIRST.BAT might buy me a pass, but alas not. – Frank Ramage Mar 08 '17 at 21:27
  • Shouldn't really be a problem. Replace the original `first.bat` with an interim `first.bat` that is identical up to the `call` and then contains instructions to replace itself with the final version. (The trick to that is to have the copy and a `goto` or `exit` command on the same line.) – Harry Johnston Mar 08 '17 at 21:29
  • Looks like I'll need to ensure NEWFIRST.BAT maintains the CALL offset in FIRST.BAT. I'm wondering how to accomplish that with an editor like UltraEdit or Notepad++... Hex mode to confirm? – Frank Ramage Mar 08 '17 at 21:33
  • "Don't use CALL second.bat. Just use SECOND.BAT" Hmmm... I wonder if I could replace CALL SECOND.BAT line with ____ SECOND.BAT (_=space) – Frank Ramage Mar 08 '17 at 21:39
  • Thanks for the help, Gents... Appreciate the extra brains on the problem. – Frank Ramage Mar 08 '17 at 21:47
  • This should explain what you need to do. http://stackoverflow.com/questions/906586/changing-a-batch-file-when-its-running – Squashman Mar 08 '17 at 23:10
  • Just a quick thought that I can't test right now. In second.bat, append a line to first.bat. **echo exit ^& copy newfirst.bat first.bat>>first.bat** – Squashman Mar 08 '17 at 23:34
  • Put this in FIRST.BAT, all in same line: `@echo Hi, I need to be placed. & CALL SECOND.BAT & GOTO :EOF`. Then, you may replace it with whichever you want... If you need to put more lines/commands in FIRST.BAT, just enclose they all in parentheses including the `GOTO :EOF` at end. – Aacini Mar 09 '17 at 02:26
  • @Aacini first.bat is local on all their computers. They can't change first.bat. – Squashman Mar 09 '17 at 03:18

0 Answers0