Function Reference


Reads all key/value pairs from a section in a standard format .ini file.

IniReadSection ( "filename", "section" )


filename The filename of the .ini file.
section The section name in the .ini file.

Return Value

Success: a 2 dimensional array where element[n][0] is the key and element[n][1] is the value.
Failure: sets the @error flag to non-zero if unable to read the section (The INI file may not exist or the section may not exist or is empty)


A standard ini file looks like:

The number of elements returned will be in $aArray[0][0]. If an @error occurs, no array is created.
    $aArray[0][0] = Number
    $aArray[1][0] = 1st Key
    $aArray[1][1] = 1st Value
    $aArray[2][0] = 2nd Key
    $aArray[2][1] = 2nd Value
    $aArray[n][0] = nth Key
    $aArray[n][1] = nth Value

Only the first 32767 chars are read for legacy reasons.


IniDelete, IniRead, IniReadSectionNames, IniRenameSection, IniWrite, IniWriteSection


#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Create an INI section structure as a string.
    Local $sSection = "Title=AutoIt" & @LF & "Version=" & @AutoItVersion & @LF & "OS=" & @OSVersion

    ; Write the string to the section labelled 'General'.
    IniWriteSection($sFilePath, "General", $sSection)

    ; Read the INI section labelled 'General'. This will return a 2 dimensional array.
    Local $aArray = IniReadSection($sFilePath, "General")

    ; Check if an error occurred.
    If Not @error Then
        ; Enumerate through the array displaying the keys and their respective values.
        For $i = 1 To $aArray[0][0]
            MsgBox($MB_SYSTEMMODAL, "", "Key: " & $aArray[$i][0] & @CRLF & "Value: " & $aArray[$i][1])

    ; Delete the INI file.
EndFunc   ;==>Example