0

I have a program for which a setting in the .ini file seems to constantly revert. I find myself constantly checking the file to see if it needs to be edited, so I would like to see if I can come up with a batch file that will do this job. The idea is to create this batch file to scan the .ini file every 2 minutes to check the value of a particular line and change the value if necessary. The line is:

UpdateSpeedCore=8

8 is the desired number for the check, but it sometimes reverts to 100.

The name of the file is prolasso.ini and the path is C:\Documents and Settings\Administrator\Application Data\ProcessLasso\config\prolasso.ini.

Thankyou to anyone who can help with this annoyance...

Edit: More on the .ini file. There are no empty lines. However, there are some lines that are set "=" to no value like "Power=". There are maybe half a dozen section delineators in the file like "[Debug]" or "[AdvancedRules]". These are not set equal to a value. It's a static length lines wise and about 100 lines long. Other than the section delineators, all the lines use an "=" sign followed by a value. These are preceded by the setting name as in "UpdateSpeedCore".

Bo McCullough
  • 13
  • 2
  • 2
  • 6

4 Answers4

4

On Windows you can use IniFile to manipulate the contents of .ini files from batch scripts. IniFile operations are idempotent.

inifile.exe "C:\Documents and Settings\Administrator\Application Data\ProcessLasso\config\prolasso.ini" UpdateSpeedCore=8
nwk
  • 4,004
  • 1
  • 21
  • 22
3

This expects the UpdateSpeedCheck=8 to be on a line by itself with no spaces.

It uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855 which you can put in the same folder.

@echo off
set "file=C:\Documents and Settings\Administrator\Application Data\ProcessLasso\config\prolasso.ini"

:loop
findstr "^UpdateSpeedCheck=8$" "%file%" >nul || (
type "%file%"|repl "^UpdateSpeedCheck=.*" "UpdateSpeedCheck=8" >"%file%.tmp"
move "%file%.tmp" "%file%" >nul
)
ping -n 120 localhost >nul
goto :loop
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • foxidrive...thankyou for this script and for REPL.bat. I'll try to learn how to use REPL.bat. Three issues. 1. The .bat works when executed manually, but it doesn't seem to be running on the ping. I get lost trying to operate a PC MS' way with the typical accounts structure, so I have ignored it entirely, and I can't create a schedule for the .bat. 2. When the script is run manually it leaves the command prompt window open. Any way to close CP in the script? 3. .ini size decreased from 9kb to 5. Compared the altered .ini file to the original, and it is the same. Any concern? – Bo McCullough Sep 19 '13 at 17:19
  • foxidrive...if it's possible I'd like to run this without the command prompt window opening. Maybe this is another question... – Bo McCullough Sep 19 '13 at 17:40
  • All resolved...found a scheduler program that will run the batch as a hidden process every 2 minutes. Can't thank you enough. Scheduler program is System Scheduler Free produced by Splinterware. – Bo McCullough Sep 19 '13 at 20:36
  • I've just returned but it's good you have a solution. You can replace the `ping` line with `timeout 120` and there is an option in task scheduler `'interact with the desktop'` or similar and you can uncheck that - but I haven't tested that feature. Your file may have been Unicode and it has been converted to Ansi which would explain the reduction in size. If it still works then it's ok. – foxidrive Sep 20 '13 at 00:59
  • Keep in mind that It will update keys in all sections. I had problems when the same keys were in different sections. – scor4er Sep 01 '17 at 16:13
1
@echo off
echo. >prolasso.new
FOR /F "delims=\= tokens=1,2" %%K IN (prolasso.ini) DO (
    IF "%%K" NEQ "UpdateSpeedCheck" (
        >>prolasso.new echo %%K=%%L
    ) else (
        >>prolasso.new echo %%K=8
    )
)
del prolasso.ini
ren prolasso.new prolasso.ini

note: this solution will delete empty lines.

edit: solved the problem with the additional space on every run (take care, that there is no space after echo %%K=%%L). This should also solve the problem with some-thousand-runs (probably because of the big line-length)

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • 1
    Nice, but it fails after ~8000 calls, as it appends each time a space at each line. And it will also delete lines beginning with `;`, but I suppose there shouldn't be such lines – jeb Sep 18 '13 at 13:48
  • Thanks Stephan. I will try the file. – Bo McCullough Sep 19 '13 at 01:50
  • Sorry Stephan. I ran the file manually from the folder containing the .ini, but it removed all the data in the .ini with the exception of an equal sign on the second line. Nothing lost, of course, but no luck. I don't know alot about batching, so I may have made a mistake, although I did attempt to follow your instructions closely. I added some info on the .ini file above if that helps... – Bo McCullough Sep 19 '13 at 02:26
  • Any other ideas? Thanks – Bo McCullough Sep 19 '13 at 02:28
  • that sounds like empty variables. Attention: those "for"-variables `%%x` are case sensitive. `%%K`is NOT equal `%%k%`! Please check those %%K adn %%L in your script. – Stephan Sep 19 '13 at 07:25
  • My fault Stephan. Had some discussions with the program developer over the last several months. He used to refer to this setting as the check rate->UpdateSpeedCheck. It should be UpdateSpeedCore. Apologies, the code failed, but nothing was removed. There was a blank line at the beginning of the new .ini. jeb's concerns I am not sure about. I will try it again later. – Bo McCullough Sep 19 '13 at 17:25
  • Thankyou Stephan. Not sure why your script wouldn't work for me in my situation. Using the script solution by foxidrive below with with a scheduler. I appreciate the effort you made. I don't know much about scripting, but it is very encouraging being able to find help this way. You guys made my day! – Bo McCullough Sep 19 '13 at 20:41
1

http://www.pixelbeat.org/programs/crudini should work on all platforms and can be used to read and update the ini file in a robust and simple way.

crudini --set prolasso.ini '' UpdateSpeedCore 8

Putting it in a loop:

:loop
crudini --set prolasso.ini '' UpdateSpeedCore 8
ping localhost -n 121 > nul
goto loop
pixelbeat
  • 30,615
  • 9
  • 51
  • 60