Resource IndexQuick Links
Infsect is an INF/INI/REG file manipulation utility for the command line, released under version 2 of the GNU General Public License. It has a number of advantages over some other INI editors, such as the ability to use the program itself to prompt for input when executed in a batch script.
While derived from a Bash script in the original incarnation of Hierma, it is a total rewrite in the C language, easily making it around 20x faster. Its original goal was to be a part of a new, DOS-based Hierma, but that has not made any progress since this program was first written, and it may very well be due for another rewrite.
As of now, this program is unreliable, and is only up here in case it is of any interest.
How to Use
If you type infsect --help, this message is displayed:
INFsect, the INI/INF/REG manipulation tool Syntax: -f [filename] -s [section] -g [field] [...] Valid arguments are: -f File name (mandatory) -s Section name (mandatory, except in a sectionless CONFIG.SYS) -g Field name (without any arguments, this retrieves its value) -v New value to write to field -i Message prompting user to write new value to field -d Use with -g to delete field -a Use with -v to append comma-terminated subvalue to field -r Use with -v to remove comma-terminated subvalue from field if it exists -4 Set REGEDIT header to version 4 -5 Set REGEDIT header to version 5
Use of this program requires at least some understanding of the structure of INF files or anything else this covers. As for how this program is used, it would be best to look at some examples...
We'll use this sample file to experiment with the tool:
[version] Signature = "$CHICAGO$" SetupClass = BASE [SectionOther] FamilyValues = NO ; Comment ;Ignore = YES DoNotIgnore = huh?, UNACCEPTABLE [Section] Value = Value1 Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS" [OtherSection] Value = Value2 Which = C:\WINDOWS [Lousy] Standalone
Retrieve a value
Here, I want to retrieve the value stored in the field Value at [Section]. To do this, I type:
infsect -f test.inf -s section -g value
and this is returned to standard output:
Note that Infsect is not case sensitive when it comes to specifying the names of sections or fields, respecting the case insensitive nature of Windows. As such, you can type a section name in all lowercase letters even if it uses title casing.
If you were to try to retrive the value from the field Ignore in [SectionOther], it would not be picked up because the field is cancelled out by a semicolon comment marker.  In the same manner, you can get the value of FamilyValues without the comment following it:
infsect -f test.inf -s sectionother -g familyvalues
If a field contains a value surrounded by quote marks, the quote marks are returned alongside the value.
infsect -f test.inf -s section -g quote
Assign a new value
To put a new value in a field, you must use -v after -g. You can use the -v option either to overwrite an existing field or create a new one.
To create a new field NewVal storing the value Purplefish, you would type:
infsect -f test.inf -s section -g NewVal -v Purplefish
As of version 0.1, an error is reported stating the field was not found, but if you check the file now, [Section] will look something like this:
[Section] NewVal = Purplefish Value = Value1 Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS"
To overwrite the value in Value with BrandNew, type:
infsect -f test.inf -s section -g value -v BrandNew
and the section will look like this:
[Section] NewVal = Purplefish value = BrandNew Quote = "C:\WINDOWS\INF;C:\WINDOWS\OPTIONS\CABS"
Note that while it knows to overwrite Value in title casing even when typing value in lowercase, Infsect also changes the casing of the field name to what the user specifies.
To enter a value surrounded by quote marks, you type: 
infsect -f test.inf -s section -g Value -v "\"Brand New\""
You can also create a new section by adding a field to it, like this:
infsect -f test.inf -s newsect -g twest -v ok
To add a value in a section without a field, omit the -g <field> argument. This is very useful in INFs when you're adding lines in a CopyFiles section or anything like that. (upon recent testing, I say you shouldn't try this right now because Infsect is very unstable and causes a segmentation fault here)
infsect -f test.inf -s Lousy -v AlsoThis
Prompt user to assign new value
Instead of dealing with extra programs like PUTINENV, you can tell Infsect to prompt the user for a value to assign when you call the program from a batch script. You can type something like this:
infsect -f test.inf -s section -g Value -i "Please enter a new value for Value: "
When run this way, the user is given the above message and must type a new value themselves before proceeding.
Please enter a new value for Value: egg
If the user inputs egg, that becomes the new value of Value. If no value is entered, the existing one remains unaffected.
Delete a field
To delete a field outright, append -d after -g <field>, like this:
infsect -f test.inf -s section -g Value -d
Manipulating subvalues within values
Comma-terminated subvalues are a frequent occurrence in INF files, maybe not so much INIs. Infsect is equipped to be able to add or remove subvalues without affecting surrounding subvalues. Try this on DoNotIgnore in [SectionOther]:
infsect -f test.inf -s SectionOther -g DoNotIgnore -v okayfine -a
and [SectionOther] changes like this:
[SectionOther] FamilyValues = NO ; Comment ;Ignore = YES DoNotIgnore = huh?, UNACCEPTABLE,okayfine
To remove a subvalue, you must specify its name. Type the following command to remove okayfine from DoNotIgnore:
infsect -f test.inf -s SectionOther -g DoNotIgnore -v okayfine -r
and the field will look just as it did before. You can most certainly remove subvalues at the beginning of a value or somewhere in the middle as well. Try this: (recent test shows that's not being handled correctly either, your mileage will vary)
infsect -f test.inf -s SectionOther -g DoNotIgnore -v huh? -r
Some things I've planned as I was programming Infsect include the ability to use directive files to conduct multiple operations on the same file all at once. This would be very important especially in DOS, since its PSP is limited to something like 127 bytes and that would make it impossible to use it for certain things like registry values stored in countless layers of keys.
Another thing, I'm not satisfied with the approach Infsect takes, even if it is around 23x faster than its Bash-based counterpart. I would like the program to store the entire contents of the working file in a 64KB buffer (up to 1MB for 32-bit environments), perform all operations in memory, and then write the new contents over the existing file afterwards.
Also, Infsect doesn't have any regard for the tidiness of INFs as it stands now. If you've got tabs or extra spaces, it always overrides them with a space next to each side of an equals sign, for instance. I would like to change this so Infsect always preserves all whitespace by default.
I'm kind of surprised I was able to do as much as I could to make Infsect fairly functional, but given I see myself needing to rewrite it a second time (since it won't run correctly under 16-bit DOS as of now), it's hard to say I'm motivated at all to try reworking it so soon. Programming is nastier than you think, because you really have to take into account how other people are going to use and break your programs... but I don't want to quit this hobby, that's for sure.
1 As of version 0.1, you can work with a commented out section if you precede it with a semicolon (and maybe a backslash depending on the shell you're using). This may not be an issue under normal usage, but it may be desirable to prevent this behavior in future versions, assuming there will be a better way to manage comments from this utility later on.
2 This was tested in Bash under FreeBSD, where most of the development took place. The need for escaped quote marks may not be applicable in a DOS prompt.
144 unique views here since February 11, 2021