Infsect is an INF/INI file manipulation utility for the command line. 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.
A bit more restructuring of the program has been put in place to adapt to the IA16-GCC compiler, which this and all future builds of Infsect will be made with in mind. The user shouldn't notice too much of a difference, but thanks to the new compiler being used, the program appears to be a lot more stable than it did when I was building it with Visual C++ 1.5. The downside is that the program is twice as large as the last version, but it should still be small enough for any floppy disk regardless.
The Win32 build is still built with Visual C++ 4.1 for the sake of static linking, so it's still not necessary to load a Visual C++ runtime package in certain early versions of Windows out of the box. If it is possible for MinGW to dynamically link to an older version of the Visual C++ runtime library than 6.0, I would be glad to use that in the future. GCC is better than any Visual C++ compiler, new or old.
Also, a bug was fixed where if the default value was entered in an interactive prompt, the last character was cut off. Now, the complete default value should be put in place (if it is specified) when receiving an empty line after an input request.
Download Infsect 0.7 (MS-DOS, 41.3 KB)
Download Infsect 0.7 (Win32, 34 KB)
Download source code (7.3 KB)
System Recommendations and Running
The supplied MS-DOS executable is compiled to run on anything as low as the Intel 8088 CPU, found in IBM XTs. It is recommended that you use MS-DOS 3.30 or later, and have 256KB of RAM or more. The Win32 executable requires Windows 95, Windows NT, or later, and is absolutely necessary for 64-bit versions of Windows.
Infsect should be highly portable to other operating systems as it only requires standard C libraries. To compile this program for something like Linux, all you need to do is run a command like this (assuming you have GCC installed):
gcc main.c -o ~/opt/bin/infsect
The -o switch followed by a path generates an executable named infsect located at opt/bin in your home directory. Make sure infsect.h is present in the same directory as main.c.
If you need to run Infsect under DOS, keep in mind that you'll be limited to working with files up to approximately 64KB in size due to inherent memory limitations. If you need to work with larger files and are working with a 32-bit or 64-bit version of Windows, get the Win32 build.
How to Use
If you type infsect -h (or no switches at all), this message is displayed:
INFSECT Usage: infsect [file] -s [section] [-g | -d] [field | field=value] [-a | -r] infsect [file] -s [section] -i [field | field=value] [-j limit] [-a | -r] infsect [file] -l infsect [file] -k [section] General switches: -s Section name (use without any other args to print) -g Read or write field value (trail with =value to write) -d Delete a field -i Interactive prompt to input value -j Character limit for interactive input (default 128) -4, -5 Force REGEDIT version 4/5 header (used with REG files) -a Append subvalue (used with -g) -r Remove subvalue (used with -g) Alternate switches: -l List all sections -k Delete a section Program information: -h Display this usage reference -v Display program version
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
When you're dealing with large files comprised of many sections, it may help to narrow your output using Infsect instead of piping the TYPE command to MORE. You can use the -l switch to list all of the sections found in a file:
infsect test.inf -l
And you get:
version SectionOther Section OtherSection Lousy
Using the -s without any additional arguments will print the contents of the specified section to the screen.
infsect test.inf -s OtherSection
Value = Value2 Which = C:\WINDOWS
Retrieve a value
Here, I want to retrieve the value stored in the field Value at [Section]. To do this, I type:
infsect 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.
If a field contains a value surrounded by quote marks, the quote marks are returned alongside the value.
infsect test.inf -s section -g quote
Assign a new value
To put a new value in a field, the same -g switch is used, but this time the field name is immediately followed by an equals symbol (=). This tells the program you intend to overwrite an existing field with a new value, or create a new field.
To create a new field NewVal storing the value Purplefish, you would type:
infsect test.inf -s section -g NewVal=Purplefish
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 test.inf -s section -g value=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. Also keep in mind that there must be NO whitespace surrounding the equals sign.
To enter a value with spaces surrounded by quote marks, you type:
infsect test.inf -s section -g Value="\"Brand New\""
\" is an escape character for a literal quote mark. The two escape quotes should be sandwiched inside the outermost standalone quote marks, which are used to actually tell the program you're writing a single argument. You can also write the command like this if desired:
infsect test.inf -s section -g "Value=\"Brand New\""
Using escaped quote marks on the outside is not necessary if you're specifying a default value for the -i switch, as that will take care of it automatically.
Depending on your command line environment, there are other kinds of characters which you may need to escape with a backslash. If you're writing a batch script, test your commands to make sure they return the intended results.
You can also create a new section by adding a field to it, like this:
infsect test.inf -s newsect -g twest=ok
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 test.inf -s section -i Value
When run this way, the user is given the above message and must type a new value themselves before proceeding.
If the user inputs egg, that becomes the new value of Value. If no value is entered, the existing one remains unaffected. If you want to use a default value when the user enters nothing, you'd type something like this:
infsect test.inf -s section -i Value=salad
This ensures that the value salad will be entered if the user doesn't input anything.
You can also limit the number of characters a user can input interactively with the -j switch:
infsect test.inf -s section -i Value=salad -j 10
Value2 (default salad, limit 10):
Excess characters from user input to stdin will be cut off.
Delete a field
To delete a field outright, replace -g with -d followed by the field name, like this:
infsect test.inf -s section -d Value
Infsect has the ability to work with comma-terminated subvalues in a field. Dealing with subvalues is common in Windows 95-style INF scripts used for installation procedures. While a normal write operation is perfectly fine for defining all of the subvalues you want to write at once to a field, it is inflexible if you are wanting to do this from a batch script where the subvalues that need to be applied may vary greatly depending on a user's choices.
Infsect has append and remove modes designed to resolve this shortcoming. By adding the -a switch, you can append a subvalue to a field without affecting the other subvalues. If the new subvalue is not already in the field, it is added to the end of the entire value after a comma. If the new subvalue already exists, it is not duplicated, but it is also moved to the end of the line nonetheless.
Using the -r switch, you can remove a subvalue from a field. If the subvalue does not exist in the field, the other subvalues remain unaffected. Also, when appending or removing subvalues, Infsect automatically cuts off any leading and/or trailing whitespace around every subvalue when performing a write operation, so as to lean down on the file size just a bit.
In the above sample INF file, there is a field labeled DoNotIgnore at the section SectionOther. It contains two subvalues, one being huh? and another being UNACCEPTABLE. Let's add a third subvalue to this with the following command:
infsect test.inf -s section -g DoNotIgnore=okay -a
Note the use of that -a switch at the end; this will activate the append mode. Using this switch, the value of DoNotIgnore is not overwritten with okay, but looks like this instead:
DoNotIgnore = huh?,UNACCEPTABLE,okay
The excess whitespace is trimmed off from the subvalues, and the new subvalue okay appears next to those preceding it. If the field specified does not exist in a section, Infsect will create it and add the new subvalue to it as if you were performing a normal write operation.
Now, we shall remove the subvalue UNACCEPTABLE from the field:
infsect test.inf -s section -g DoNotIgnore=UNACCEPTABLE -r
And you get:
DoNotIgnore = huh?,okay
Modifying Registry Scripts
Because .REG scripts share a very similar syntax to INI/INF files, Infsect can be used to modify such registry editor scripts. When you modify a file with a .REG extension, Infsect automatically knows to give the file special treatment, which is really nothing more than being mindful to apply a version header to the top of the file.
Using the -4 or -5 switches, you can change the registry editor version header on the fly with any write operation. If you are creating a new registry script, Infsect defaults to using the REGEDIT4 header used by Windows 95, 98, ME, and NT 4.0. If you plan to work with systems running Windows 2000 or later, it's best to apply the -5 switch every time you want to create or modify a registry script, though Infsect will leave an existing registry version header untouched if it already exists.
Even though the syntax is technically the same otherwise, you should be mindful that the Registry Editor in Windows always surrounds field names in quote marks, as well as values if they are strings (binary values are not encapsulated in quotes). You'll need to employ some escaped quotes and possibly escaped backslashes (that is, precede such characters with a backslash). You'd have to write a command like this:
infsect test.reg -s HKEY_LOCAL_MACHINE\USERS\.DEFAULT -g \"OkayProcedure\"=\"1\"
Depending on the shell you're working with (or maybe just how the program was compiled), you may need to use double backslashes; this is definitely the case when compiling Infsect using GCC and running it under Bash. However, double backslashes may be taken literally in the MS-DOS or Windows command prompts. I hope I can fix this inconsistency in a future release, but in the offchance you are writing a script designed to be run under Linux, you might consider surrounding static values with single quote marks to avoid the need for double backslashes.
Obviously, Infsect has to get back up to par with what it was earlier. The "start small" approach worked very well and may be enough for most people, but just in case, I might want to add more things to it like the ability to manipulate subvalues within values later on when I get the time.
Now that Infsect is in a decent position, it'll also allow me to bring about a really cool guide in the future which will need this program. Beyond that, it's not much, but it's a small victory in the way of getting myself into the kind of programming I want to do.