TIniFile.ReadSections returns too many entries when reading win.ini

Posted on 2006-04-10
Last Modified: 2012-06-27
Hi All,
A simple conundrum for me:  When using the method TIniFile.ReadSections to return the section names of a Win XP .ini file I notice that in the case of the Windows .ini files, for example, system.ini and win.ini, the method returns more entries than there are actually in the file when I compare by opening the real file in an editor.  Could someone explain how and why these files are treated differently by a method call that returns the correct list in all other cases that I have tested and, perhaps, where these other entries come from?

Question by:namuh1
    LVL 26

    Accepted Solution


    The profile calls to get/write info can get mapped to the registry for NT based systems (like XP). The help file documents this as follows:

    Calls to private profile functions may be mapped to the registry instead of to the specified initialization files. This mapping occurs when the initialization file and section are specified in the registry under the following keys:
            Windows NT\CurrentVersion\IniFileMapping
    This mapping is likely if an application modifies system-component initialization files, such as CONTROL.INI, SYSTEM.INI, and WINFILE.INI. In these cases, the GetPrivateProfileString function retrieves information from the registry, not from the initialization file; the change in the storage location has no effect on the function's behavior.

    The Win32 Profile functions (Get/WriteProfile*, Get/WritePrivateProfile*) use the following steps to locate initialization information:

    1.      Look in the registry for the name of the initialization file, say myfile.ini, under IniFileMapping:

            Windows NT\CurrentVersion\IniFileMapping\myfile.ini

    2.      Look for the section name specified by lpAppName. This will be a named value under myfile.ini, or a subkey of myfile.ini, or will not exist.
          3.      If the section name specified by lpAppName is a named value under myfile.ini, then that value specifies where in the registry you will find the keys for the section.
          4.      If the section name specified by lpAppName is a subkey of myfile.ini, then named values under that subkey specify where in the registry you will find the keys for the section. If the key you are looking for does not exist as a named value, then there will be an unnamed value (shown as "<No Name>") that specifies the default location in the registry where you will find the key.

    5.      If the section name specified by lpAppName does not exist as a named value or as a subkey under myfile.ini, then there will be an unnamed value (shown as "<No Name>") under myfile.ini that specifies the default location in the registry where you will find the keys for the section.
          6.      If there is no subkey for myfile.ini, or if there is no entry for the section name, then look for the actual myfile.ini on the disk and read its contents.

    When looking at values in the registry that specify other registry locations, there are several prefixes that change the behavior of the ini file mapping:
    ! - this character forces all writes to go both to the registry and to the .INI file on disk.
    # - this character causes the registry value to be set to the value in the Windows 3.1 .INI file when a new user logs in for the first time after setup.
    @ - this character prevents any reads from going to the .INI file on disk if the requested data is not found in the registry.

    USR: - this prefix stands for HKEY_CURRENT_USER, and the text after the prefix is relative to that key.
    SYS: - this prefix stands for HKEY_LOCAL_MACHINE\SOFTWARE, and the text after the prefix is relative to that key.



    Author Comment

    Many thanks for such a thorough and useful answer!


    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now