![]() ![]() ![]() ![]() ![]() ![]() |
|||||||||||||||||||
![]() |
|||||||||||||||||||
Created on March 10, 2023
The INF setup engine includes its own mechanism for modifying other INI files. INI files are regarded as easier to manage, though the lines in an UpdateInis section require a syntax that may get kind of hard to read at times. This page will cover the essentials as well as clarify a few ambiguous-looking things, especially in regards to quote marks. Unlike with files and the registry, there are not two directives for adding and deleting entries in INI files. There is only one directive that manages it all. Adding EntriesThe syntax here isn't too complicated; each line addresses a new or existing entry in a section of an INI file. The parameters are as follows, from left to right:
For our purposes, we'll define a new section for managing INI entries labeled New.Ini, with the trailing .Ini being a convention for indicating what this section is used for.
Because you're going to be working with a file, you have to tell the INF to point to it. You can technically write this as you normally would:
However, the string expansion discussed earlier also works with LDIDs, and you don't have to (and shouldn't) define them in a Strings section. If you want to work with the INI file located at the root of the drive where Windows is installed, write this:
It's always good practice to use LDIDs to ensure you get consistent results across varied Windows installations. When you execute an installation, the INF should call the New.Ini section to create or update the TEST.INI file at the root of the drive, returning something like this:
The operation was executed exactly how we wanted it to be... was it? Our program using the INI file may prefer to have the value surrounded in quote marks. Doing that within quote marks themselves sounds outlandish when there's no proper-looking escaping mechanism like in a programming language such as C, but you can write two adjacent quote marks to output a literal quote mark.
And you should see that your entry in TEST.INI now has quote marks surrounding the value. You can pass this same literal quote mark to registry values as well. Also note that it did not create a new key with the same name, only updated the existing one. It is considered invalid to have duplicate labels for entries in a section. If you want a value to be updated only on the condition it matches a key or value, specify something for the old entry parameter. To match only the key, use this:
To match only the value, write this:
To match both the key and value, write this:
While it looks like you'd get the same effect as before, if the key and/or value did not exist in the section based on the conditions you've given, the replacement entry would not be created. Try deleting TEST.INI and execute the installation with such conditions applied; all you would get is the header for the section NewSect. Deleting EntriesDeleting INI entries should be simple enough, but because only one directive is used for managing INI entries, you cannot use the same UpdateInis section for both installation and uninstallation as you'd want to. It is necessary to create a new section for this task. We'll define our new section as Uninstall.Ini, and you'll notice that I leave the parameter for the new entry empty:
After executing an uninstallation, you should see in TEST.INI that the entry is gone, leaving NewSect empty. To delete an entry only on the condition that both the key and value match what exists in the section, you need to apply the flag 1 at the last parameter, which is written as:
Using this flag, the entry is not touched if the value is GARAGE SALE ?, but will be deleted if it has an exclamation point instead. The setup engine is not capable of deleting sections. If you really need to clean out an INI file, your best bet is to delete it in a DelFiles directive. Never delete INIs integral to Windows, such as WIN.INI or SYSTEM.INI. If you're wanting to modify INI files via a batch script using a simpler method, you may wish to try my own command line program, Infsect. Here is what our INF file looks like now:
Don't forget to leave whitespace at the end of the file.
Comments
There are a few specification documents on the compression algorithm which in theory would let me be able to build a replacement that scales better on modern systems but I am so busy in college at the time I am typing this... 1 comment on this page Sort: Ascending | Descending Leave a Comment |
|||||||||||||||||||
|