Question : Script to open up .ini file, make changes, then save

i have an application that requires manually edits to an .ini file in order to turn on debug level logging.  I would like to have a script that can do the following steps, and another script to reverse the changes.

-stop specified services
-open .ini file
-change 3 entries in the .ini file
-save the file
-start the service back up.


Note:  the three entries that need to be updated are

Debug=0 to Debug=2
wantLogs=false  to wantLogs=true
wantTimings=false to wantTimings=true
WantVerbose=false to wantVerbose=true

Answer : Script to open up .ini file, make changes, then save

Okay, attached is the BAT script that should do the job.  You'll need to adjust as needed with the name of the INI file, the name of the services, etc.  Also, you will need to download inifile.exe from the following link and place it with the BAT folder so it can be run:

http://home.mnet-online.de/horst.muc/wbat32.htm#inifile

The SC command takes the name of the service, not it's title, so you should do a SC QUERY at a command prompt first and look for the name of the services you need to stop / start.

You can create the second script from this one once you get it working, just give it a different name and change the values updated in the INI file.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
@echo off
 
REM Define location of INI file to update,m and LOG files to delete
set IniFile=c:\temp\file.ini
set LogsDir=c:\opentext\livelink\logs
 
REM Stop related services
sc stop service1
sc stop service2
 
REM Update values in INI file
inifile %IniFile% [general] Debug=0
inifile %IniFile% [options] wantLogs=false
inifile %IniFile% [options] wantTimings=false
inifile %IniFile% [options] wantVerbose=false
 
REM Clean LOG file directory
del /F /Q %LogsDir%\*
 
REM Start related services
sc start service1
sc start service2
Random Solutions  
 
programming4us programming4us