Jump to content

Attempt at improved inireadsection

Recommended Posts


Hello, all..

My AutoIT is pretty terrible - but I get by with trawling here :)

I came across an issue where i had to parse a large key in a large ini file, and found that I was victim of inireadsection's limit of "Only the first 32767 chars are read for legacy reasons."


I've attempted to put together some terrible code that parses an ini section.

It's absolutely nowhere near good, but I figured I'd put it here so that folk who know what they're doing can laugh at improve it.

$Ini = @ScriptDir & "\bigini.ini"
Dim $IniArray[0][2]

$KeyName = "Person"

$R = FileOpen($Ini, 0)
$IniStr = FileRead($R)

$Start = StringInStr($iniStr, "[" & $KeyName & "]")

    If $Start = 0 then
    Msgbox(16, "Error", "String not found")

$Stop = StringInStr($IniStr, @CRLF & "[", 0, 1, ($Start + 1))
    If $Stop = 0 then
    $Stop = StringLen($IniStr)

$String = StringMid($IniStr, $Start, ($Stop - $Start))
$Split = StringSplit($String, @CRLF, 1)
$KeyCount = 0
Dim $IniArray[65535][2]

    For $Loop = 1 to $Split[0]
    $Add = "Y"
    $Str = $Split[$Loop]
    $EQBreak = StringInStr($Str, "=")
        Case StringMid($Str, 1, 1) = ";"
        $Add = "N"
        Case $EQBreak = 0
        $Add = "N"
        Case Else
        $Add = "Y"
        If $Add = "Y" then
        $KeyCount = $KeyCount + 1
        $Key = StringMid($Str, 1, ($EQBreak - 1))
        $Val = StringMid($Str, ($EQBreak + 1))
        $IniArray[$KeyCount][0] = $Key
        $IniArray[$KeyCount][1] = $Val

Redim $IniArray[$KeyCount +1][2]

; Add the number of hits to 00 to match inireadsection
$IniArray[0][0] = $KeyCount


; Do stuff with the Array like you would inireadsection


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • kartune
      By kartune
      Hi, i would like to know if there is a possible way to use subsections for ini files?
      For example, my ini file would look something like this:
      [[JAN]] <----- subsection
      [[JAN]] <----- subsection
      [[JAN]] <----- subsection
      The sales would be inputed everyday by the script, and then whenever viewed, i would be using an array to view every sale/cost/profit under the subsection
      Thanks for your time!
    • RC86
      By RC86
      Afternoon, I could very well be doing this wrong so feel free to totally advise otherwise - I'm wanting to use a GUI to first display a key from within an INI file, then secondly change the INI file by using a FileSelectFolder command but then I want to see the GUI change to reflect the change I've just made.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) $Input1 = GUICtrlCreateInput(Iniread(@WorkingDir & "\test.ini","Path","FilePath",""), 64, 80, 121, 21) $Button1 = GUICtrlCreateButton("Change", 200, 80, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $selectedFolder = FileSelectFolder("Select Log Path Directory",@WorkingDir,0) If NOT $selectedFolder = "" Then $newLogPath = IniWrite(@WorkingDir & "\test.ini","Path","FilePath",$selectedFolder) EndIf EndSwitch WEnd So 2 part question really: (1) Should I be using GUICtrlCreateInput to display my INI read from within the GUI? (2) How can I refresh the GUI to update that to read the new information I've just written to the GUI?

    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I was working on a script which read the content of a .ini file to retrieve the file that has to open, and, based on the value of a second key stored in the .ini file, set the window on top, minimized or maximized...
      I did something like this, but seems to not work properly...
      Could anyone please tell me what I'm doing wrong?
      Thank you  
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> ;#include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioneIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioneIni[2][1]) Case $aSezioneIni[2][1] = "MIN" ToolTip("MIN", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE) Case $aSezioneIni[2][1] = "MAX" ToolTip("MAX", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE) Case $aSezioneIni[2][1] = "TOP" ToolTip("TOP", 0, 0) WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf And the .ini file is like this:
      [CONFIGURAZIONE_EXE] PercorsoExe=Here goes the path and the .exe to execute ModalitaAperturaExe=Here goes one of the value below /* TOP Shows the windows on top */ /* MIN Shows the window minimized */ /* MAX Shows the window maximized */  
    • Wingens
      By Wingens
      Hi I am trying to read multiple sections from an ini file into an array and use the result to calculate how many records there are from the suppliers and this devided into the status records that belong to it. The problem I am having; I am able to use Ubound to calculate how many record there are in total to the option chosen from the combo box, but where I am getting stuck is the part to link the status and leverancier to each other and count them.
      Hope some one can help me.
      My code right now:
      #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> $Form1 = GUICreate("Form1", 615, 437, 569, 253) $LEVCOMBO = GUICtrlCreateCombo("", 184, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) Global $aSections = IniReadSectionNames(@ScriptDir & "\leveranciers.ini") If (Not @Error) Then GUICtrlSetData($LEVCOMBO, _ArraytoString($aSections, "|", 1), $aSections[1]) $LABEL = GUICtrlCreateLabel("Totaal aantal RMA aanvragen: ", 48, 200, 250, 21) $TOTALCOUNT = GUICtrlCreateLabel("", 200, 200, 100, 21) $LABEL2 = GUICtrlCreateLabel("Aantal aangevraagd: ", 48, 225, 250, 21) $TOTALAANGEVRAAGD = GUICtrlCreateLabel("", 200, 225, 100, 21) $LABEL3 = GUICtrlCreateLabel("Aantal verzonden: ", 48, 250, 250, 21) $TOTALVERZONDEN = GUICtrlCreateLabel("", 200, 250, 100, 21) $LABEL4 = GUICtrlCreateLabel("Aantal afgehandeld: ", 48, 275, 250, 21) $TOTALAFGEHANDELD = GUICtrlCreateLabel("", 200, 275, 100, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $LEVCOMBO COMBO() EndSwitch WEnd Func COMBO() Local $hINI_FILENAME = @ScriptDir & "\ini.ini" $READAANGEVRAAGDRMA = IniReadSection($hINI_FILENAME, 'LEVERANCIER') $READSTATUS = IniReadSection($hINI_FILENAME, 'STATUS') $VAR = GUICtrlRead($LEVCOMBO) $READAANGEVRAAGDRMACOUNT = _ArrayFindAll($READAANGEVRAAGDRMA, $VAR, Default, Default, Default, Default, 1) GUICtrlSetData($TOTALCOUNT,UBound($READAANGEVRAAGDRMACOUNT)) $nb = $READAANGEVRAAGDRMA[0][0] Local $res[$nb+1][3] $res[0][0] = $nb For $i = 1 to $nb $res[$i][0] = $READAANGEVRAAGDRMA[$i][1] $res[$i][1] = $READSTATUS[$i][1] Next _ArrayDisplay($res) EndFunc And the ini files that goes with it:
      [STATUS] 1=Afgehandeld 3=Verzonden 4=Aangevraagd 5=Aangevraagd 6=Aangevraagd 7=Aangevraagd 8=Verzonden 9=Aangevraagd 10=Aangevraagd 11=Aangevraagd 12=Aangevraagd 13=Aangevraagd 14=Aangevraagd 15=Aangevraagd 16=Aangevraagd 17=Aangevraagd 18=Aangevraagd 19=Aangevraagd 20=Aangevraagd 21=Aangevraagd 22=Aangevraagd [LEVERANCIER] 9=Dobit B.V. 1=Dobit B.V. 10=Dobit B.V. 11=Dobit B.V. 12=Dobit B.V. 13=Dobit B.V. 14=Asus 15=Asus 16=Brother 17=Dobit B.V. 18=Dobit B.V. 19=Dobit B.V. 20=Dobit B.V. 21=Dobit B.V. 22=Asus leveranciers.ini:
      [Kies een leverancier...] [Dobit B.V.] URL =http://eline.dobit.be/eline/master.php [TechData B.V.] URL = [MaxICT B.V.] URL = [Brother] URL= [Asus] URL=https://eu-rma.asus.com/pickup_europe/pickup.aspx?country=nl [HP] URL= [Lenovo] URL= [CCV] URL=  

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.