I'm looking for help with the following scenario. I am a bit of a
novice at working with batch files. We are setting up a master batch
file to perform an unattended install of 3 applications. The
simplified format is as follows:
Master batch file
setup.exe <path to INI file> [App 1]
call batch2.cmd [App 2]
call batch3.cmd [App 3]
The problem we're running into is with the INI file for the first app.
One of the parameters in the INI file is for the application
password, which we don't want to leave saved in the INI file. Also,
there is one other parameter that may vary.
What we'd like to be able to do is run the master batch file with two
parameters and have the INI file get modified with these parameters.
IOW, we would run something like this:
master.bat password Other_parameter
The INI file is standard, with Parameter=<value> format. How do I go
about taking the command line parameters for master.bat and modify the
INI file? I don't care if we take the existing INI file on a network
share, copy it locally, modify it with the command line parameters,
execute it, and then delete the INI file at the end of the process.
Thanks for any help you can provide,
Dave
^ Master batch file
^ setup.exe <path to INI file> [App 1]
^ call batch2.cmd [App 2]
^ call batch3.cmd [App 3]
^ The INI file is standard, with Parameter=<value> format. How do I go
^ about taking the command line parameters for master.bat and modify the
^ INI file?
Save the initialization file as a master that does not get altered and
create a second initialization file at runtime, that you will later delete,
which contains the secret information. Append the secret information to the
second initialization file with the "append" redirection operator. For
example:
COPY InitMaster.ini init.ini
Echo Password=%1>>init.ini
Echo Parameter=%2>>init.ini
setup.exe <path to INI file> [App 1]
Erase init.ini
Frank
How easily can you do this if the parameters are scattered about in
the INI file? So if we have a seventy line INI file, say the
Parameter value gets set on lines 34 and 40, and the Password gets set
on line 50. IOW, the INI file is in this format:
Misc INI settings
....
Parameter=
....
Parameter=
....
Password=
....
End of INI file
Thanks for your help,
Dave
------------------------begin screen capture WinNT 4.0 SP6a----------------------
C:\cmd>type c:\temp\yourfile.ini
Misc INI settings
....
Some stuff here
Parameter=oldparm
[New Section]
Here is more stuff=something
Parameter=oldparm
Garbage=whatever
Password=oldpassword
End of INI file
C:\cmd>demo\updinifile c:\temp\yourfile.ini c:\temp\yournewfile.ini NeWpAsSwOrD NeWpArAmEtEr
C:\cmd>type c:\temp\yournewfile.ini
Misc INI settings
....
Some stuff here
Parameter=NeWpArAmEtEr
[New Section]
Here is more stuff=something
Parameter=NeWpArAmEtEr
Garbage=whatever
Password=NeWpAsSwOrD
End of INI file
C:\cmd>qblist demo\updinifile.cmd
===== begin file C:\cmd\demo\updinifile.cmd =====
01. @echo off
02. set OldIniFile=%1
03. set NewIniFile=%2
04. set NewPassword=%3
05. set NewParameter=%4
06. if exist %NewIniFile% del %NewIniFile%
07. for /f "tokens=1* delims=:" %%a in (
08. 'type %OldIniFile% ^| findstr /n /v /c:"CoLoRlEsS gReEn IdEaS"'
09. ) do call :rewrite "%%b"
10. goto :EOF
11. :rewrite
12. set line=""%1""
13. set line=%line:"""=%
14. if "%line:~0,8%" EQU "Password" (
15. set line=Password=%NewPassword%
16. )
17. if "%line:~0,9%" EQU "Parameter" (
18. set line=Parameter=%NewParameter%
19. )
20. if not defined line (
21. echo.>>%NewIniFile%
22. ) else (
23. echo>>%NewIniFile% %line%
24. )
25. goto :EOF
===== end file C:\cmd\demo\updinifile.cmd =====
-----------------------------end screen capture WinNT 4.0 SP6a-------------------------
Phil Robyn
Univ. of California, Berkeley
--
u n z i p m y a d d r e s s t o s e n d e - m a i l
^ How easily can you do this if the parameters are scattered about in
^ the INI file?
Normally the position in the initialization file is not important. If the
program uses the GetPrivateProfileSection() or GetPrivateProfileString()
API functions to get the appropriate lines then they would need to be under
the applicable [section] header, which you could position at the end of the
file before appending the new lines. If the program reads the file on its
own then line position is probably not important.
Frank
Dave
Phil Robyn <pro...@uclink.berkzipeley.edu> wrote in message news:<3BBA3990...@uclink.berkzipeley.edu>...