Pergunta

I am installing software on a client machine, so I have a configuration file having over 100 variables, so I want to change these variables at run time using batch file.

Here are some of variables for example-

file name: config.asp ...

USPSAccessKey=fsfsfs113bh$dd
USPSUserID=1232445
USPSPassword=#########
USPSServiceCode=PRIORITY
USPSServiceCodeFixed=YES
USPSPackageType=VARIABLE
USPSCustomerClassCode=FLAT

...

So there is any way to read this file and then change variables using batch file

Thanks in advance,

Foi útil?

Solução

Your question is not clear. If you want to modify config.asp file in order to change certain lines with different values, then you may do this:

@echo off
setlocal EnableDelayedExpansion

rem Define new values of desired variables
set newValue[USPSUserID]=5442321
set newValue[USPSPassword]=$$$$$$$$$

(for /F "tokens=1,2 delims==" %%a in (config.asp) do (
   set "value=%%b"
   if defined newValue[%%a] set value=!newValue[%%a]!
   echo %%a=!value!
)) > newConfig.asp

Outras dicas

This should do it.

First read the file with a for loop, then modify some values, then write the variables out using set with redirecting the output. Note: I use config2.asp for the output so you can test if it works first.

@echo off
setlocal enableextensions enabledelayedexpansion

for /f "delims=" %%I in (config.asp) do set "%%I"

:: Set some USPS variables here
::


set USPS > config2.asp
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top