Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to pass command line parameters to INI file

1,068 views
Skip to first unread message

Dave

unread,
Oct 2, 2001, 8:19:03 AM10/2/01
to
Hi,

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

Frank

unread,
Oct 2, 2001, 10:18:58 AM10/2/01
to
Dave <3d09d6c6.01100...@posting.google.com>...

^ 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

Dave

unread,
Oct 2, 2001, 4:45:31 PM10/2/01
to
"Frank" <choqu...@dartmgjvujcymfee.com> wrote in message news:<01c14b4d$22b11480$0125250a@dartmgjvujcymfee>...

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

Phil Robyn

unread,
Oct 2, 2001, 6:02:56 PM10/2/01
to
Dave wrote:

------------------------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


Frank

unread,
Oct 2, 2001, 7:41:17 PM10/2/01
to
Dave <3d09d6c6.01100...@posting.google.com>...

^ 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

unread,
Oct 24, 2001, 5:11:37 PM10/24/01
to
Sorry for the late reply, but your procedure below did the trick.
Thanks for all of your help!

Dave


Phil Robyn <pro...@uclink.berkzipeley.edu> wrote in message news:<3BBA3990...@uclink.berkzipeley.edu>...

0 new messages