0

I cannot use VB Script and I have to accomplish this task in one single .bat file. Can you please help me run both items simultaneously?

  1. add registry key command
  2. carry out an IF statement and commands

Add to registry:

REGEDIT4

;@start regedit /s "%~f0"&goto :eof

[HKEY_LOCAL_MACHINE\Software\TEST]

Carry out my task:

:CheckOS

IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)

:64BIT

setlocal ENABLEDELAYEDEXPANSION

set filein="c:\Program Files (x86)\Premier MDC\mdt.ini"

set fileout="c:\Program Files (x86)\Premier MDC\mdtnew.ini"

set fileold="c:\Program Files (x86)\Premier MDC\mdtold.ini"

set old=10.17.8.64

set new=10.253.0.1

for /f "tokens=* delims=¶" %%i in ( '"type %filein%"') do (

set str=%%i

set str=!str:%old%=%new%!

echo !str! >> %fileout%)

move %filein% %fileold%

move %fileout% %filein%

GOTO END

:32BIT

setlocal ENABLEDELAYEDEXPANSION

set filein="c:\Program Files\Premier MDC\mdt.ini"

set fileout="c:\Program Files\Premier MDC\mdtnew.ini"

set fileold="c:\Program Files\Premier MDC\mdtold.ini"

set old=10.17.8.64

set new=10.253.0.1

for /f "tokens=* delims=¶" %%i in ( '"type %filein%"') do (

set str=%%i

set str=!str:%old%=%new%!

echo !str! >> %fileout%)

move %filein% %fileold%

move %fileout% %filein%

GOTO END

:END

I have tested these independently from each other in seperate .bat files and they work perfectly. I just need help combining them into one file and have it run both tasks. Thanks.

Community
  • 1
  • 1
Jc Meyer
  • 17
  • 9
  • A [duplicate](http://stackoverflow.com/questions/130193/is-it-possible-to-modify-a-registry-entry-via-a-bat-cmd-script)? (tl;dr you don't need a separate .reg file, see the link for the examples) – wOxxOm Jul 15 '15 at 19:34
  • It's not duplicated code at all. One half has (x86) in the paths and the other does not. There are no duplicates at all. Half of the computers are 64 bit and the other are 32 bit. The folder scheme is different with both of them involving only 32 bit programs which nest them inside of a (x86) folder. – Jc Meyer Jul 16 '15 at 14:16

1 Answers1

1

In addition to changes suggested by @xOxxOm... You have a lot of duplicated code. This is difficult to maintain because any changes need to be made in 2 places. Change to something like this:

set "PF=%ProgramFiles%
if exist "%ProgramFiles(x86)%" set "PF=%ProgramFiles(x86)%"
setlocal ENABLEDELAYEDEXPANSION
set filein="%PF%\Premier MDC\mdt.ini"
set fileout="%PF%\Premier MDC\mdtnew.ini"
set fileold="%PF%\Premier MDC\mdtold.ini"
. . . (one set of your duplicated code here)
RGuggisberg
  • 4,630
  • 2
  • 18
  • 27