;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; AutoIt Version: 3.3.0.0 ;; ;; ;; ;; Template AutoIt script. ;; ;; ;; ;; AUTHOR: TheSaint ;; ;; ;; ;; SCRIPT FUNCTION: Create and Use a (Virtual) INI file like structure in Memory ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; FUNCTIONS ; _Ini_AddUpdate($ini_virtual, $virtual_section, $virtual_key, $virtual_value = "") ; _Ini_Close($ini_virtual) ; _Ini_Create($virtual_section, $virtual_key, $virtual_value = "") ; _Ini_Inform($ini_virtual, $virtual_show = "") ; _Ini_KeyNames($ini_virtual, $virtual_section) ; _Ini_Open($ini_fle) ; _Ini_Read($ini_virtual, $virtual_section, $virtual_key = "", $virtual_report = "") ; _Ini_Remove($ini_virtual, $virtual_section, $virtual_key = "") ; _Ini_Rename($ini_virtual, $virtual_section, $virtual_new, $virtual_key = "") ; _Ini_Save($ini_virtual, $ini_fle) ; _Ini_SectionNames($ini_virtual) ; _Ini_Show($ini_virtual, $virtual_section = "", $virtual_title = "") ; _Ini_WriteSection($ini_virtual, $virtual_data, $virtual_section, $virtual_replace = 0) ; NOT YET FULLY IMPLEMENTED ; _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, $virtual_job) ; NOT YET IMPLEMENTED ; _Ini_CopySection($ini_virtual, $virtual_section, $virtual_newsect) ; _Ini_Log (maybe) #Include Func _Ini_AddUpdate($ini_virtual, $virtual_section, $virtual_key, $virtual_value = "") ; Add a Section (one key) or Key to an existing INI structured variable, or update a Value for a Key. Local $ini_data, $ini_end, $ini_part, $ini_sect, $key_part, $pos, $sect $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "add") = 0 Then SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf $virtual_section = "[" & $virtual_section & "]" $sect = $virtual_section & Chr(13) & Chr(10) If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. $parts = StringSplit($ini_virtual, $sect, 1) ; Section to work with and remainder of INI structure, if any. $ini_sect = $parts[2] $pos = StringInStr($ini_sect, Chr(13) & Chr(10) & "[") If $pos > 0 Then ; Start of next section $ini_end = StringMid($ini_sect, $pos) ; Section being worked with $ini_sect = StringLeft($ini_sect, $pos - 1) Else ; No next section $ini_end = Chr(13) & Chr(10) EndIf $ini_sect = StringStripWS($ini_sect, 2) $ini_sect = Chr(13) & Chr(10) & $ini_sect If StringInStr($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=") > 0 Then ; Key found, check/update Value. $portion = StringSplit($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=", 1) ; Part of Section after Key $key_part = $portion[2] $pos = StringInStr($key_part, Chr(13) & Chr(10)) If $pos > 0 Then ; Start of more Keys in Section $ini_part = StringMid($key_part, $pos) ; Value for Key in Section $key_part = StringLeft($key_part, $pos - 1) Else ; No more Keys in Section $ini_part = "" EndIf If $key_part == $virtual_value Then ; Return INI structure without any changes Return $ini_virtual Else ; Rebuild a bit of INI structure with part of Section before Key, Existing Key, new Value, ; plus Remaining structure of INI (including any remaining Keys and/or Sections). $ini_sect = $portion[1] & Chr(13) & Chr(10) & $virtual_key & "=" & $virtual_value & $ini_part & $ini_end EndIf Else ; Key not found, add Key & Value. ; Rebuild a bit of INI structure with original Section, plus new Key & Value, plus remaining ; INI structure (other Sections if any). $ini_sect = $ini_sect & Chr(13) & Chr(10) & $virtual_key & "=" & $virtual_value & $ini_end EndIf ; Reassemble INI structure from part before Section, Section Name, plus rebuilt portion of ; changed or added parts (Key &/or Value). $ini_data = $parts[1] & $virtual_section & $ini_sect Else ; Section not found, add Section, Key & Value. ; Compile from original INI structure and new Section plus Key & Value. $ini_data = $ini_virtual & $virtual_section & Chr(13) & Chr(10) & $virtual_key & "=" & $virtual_value & Chr(13) & Chr(10) EndIf ; Return INI structure with Section or Key added or Value updated Return $ini_data EndFunc ;=> _Ini_AddUpdate Func _Ini_Close($ini_virtual) ; Deliberate zeroing of what could potentially be a variable with very large data. $ini_virtual = "" Return $ini_virtual EndFunc ;=> _Ini_Close Func _Ini_Create($virtual_section, $virtual_key, $virtual_value = "") ; Create an INI structured variable. $ini_virtual = "" $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "create") = 0 Then SetError(1, 0, 0) Return "" EndIf $ini_virtual = "[" & $virtual_section & "]" & Chr(13) & Chr(10) & $virtual_key & "=" & $virtual_value & Chr(13) & Chr(10) Return $ini_virtual EndFunc ;=> _Ini_Create Func _Ini_Inform($ini_virtual, $virtual_show = "") ; Report on character, word & byte count of existing INI structured variable. Local $ans, $ini_bytes, $ini_chars, $ini_words, $ini_report $ini_chars = StringLen($ini_virtual) $ini_data = StringReplace($ini_virtual, "[", "") $ini_data = StringReplace($ini_data, "]", "") $ini_data = StringReplace($ini_data, "=", " ") $ini_data = StringReplace($ini_data, Chr(13) & Chr(10), " ") $ini_words = StringSplit($ini_data, " ", 1) $ini_words = $ini_words[0] - 1 $ini_bytes = StringToBinary($ini_virtual, 1) $ini_bytes = BinaryLen($ini_bytes) If $virtual_show = 1 Then $ini_report = "Characters = " & $ini_chars & @LF & _ "Words = " & $ini_words & @LF & "Bytes = " & $ini_bytes & @LF $ans = MsgBox(262465, "INI Information", $ini_report & @LF & _ "OK = Send detail to clipboard.", 0) If $ans = 1 Then ClipPut($ini_report) EndIf EndIf Return $ini_chars & "|" & $ini_words & "|" & $ini_bytes EndFunc ;=> _Ini_Inform Func _Ini_KeyNames($ini_virtual, $virtual_section) ; List all Keys in a Section in an existing INI structured variable. Local $ini_data, $ini_part, $ini_sect, $key_part, $parts, $pos, $sect $virtual_key = "" $virtual_value = "" $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "keys") = 0 Then SetError(1, 0, 0) Return "" EndIf $sect = "[" & $virtual_section & "]" If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. $parts = StringSplit($ini_virtual, $sect, 1) ; Start of section to work with until the end of INI structure. $ini_sect = $parts[2] ; Determine where Section ends $pos = StringInStr($ini_sect, Chr(13) & Chr(10) & "[") If $pos > 0 Then ; Portion to work with. $ini_sect = StringLeft($ini_sect, $pos - 1) EndIf $ini_data = "" $parts = StringSplit($ini_sect, Chr(13) & Chr(10), 1) For $pos = 1 To $parts[0] $ini_part = $parts[$pos] If StringInStr($ini_part, "=") > 0 Then $key_part = StringSplit($ini_part, "=", 1) $key_part = $key_part[1] $ini_data &= $key_part & "|" EndIf Next ; Remove trailing pipe if exist (if result is not blank). $ini_data = StringTrimRight($ini_data, 1) Else ; Section not found, no Keys to report. SetError(1, 0, 0) Return "" EndIf ; Return Keys found in Section. Return $ini_data EndFunc ;=> _Ini_KeyNames Func _Ini_Open($ini_fle) ; Load an existing INI file into an INI structured variable. Local $file, $ini_data, $keyval, $l, $lines, $p, $parts, $read If FileExists($ini_fle) Then $file = FileOpen($ini_fle, 0) $read = FileRead($file) FileClose($file) $ini_data = $read Return $ini_data Else MsgBox(262192, "Path Error", "INI file not found!", 0) SetError(1, 0, 0) Return "" EndIf EndFunc ;=> _Ini_Open Func _Ini_Read($ini_virtual, $virtual_section, $virtual_key = "", $virtual_report = "") ; Read a Section or Key from an existing INI structured variable. Local $ini_data, $ini_end, $ini_part, $ini_sect, $key_part, $parts, $portion, $pos, $sect $virtual_value = "" $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "read") = 0 Then SetError(1, 0, 0) Return "" EndIf $virtual_section = "[" & $virtual_section & "]" $sect = $virtual_section & Chr(13) & Chr(10) If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. $parts = StringSplit($ini_virtual, $sect, 1) ; Start of section to work with until the end of INI structure. $ini_sect = $parts[2] $pos = StringInStr($ini_sect, Chr(13) & Chr(10) & "[") If $pos > 0 Then ; Start of next section $ini_end = StringMid($ini_sect, $pos) ; Section being worked with $ini_sect = StringLeft($ini_sect, $pos - 1) $ini_sect = $ini_sect & Chr(13) & Chr(10) Else ; No next section $ini_end = "" EndIf $ini_sect = Chr(13) & Chr(10) & $ini_sect If $virtual_key = "" Then ; No Key specified, so return data for Section. $ini_data = $virtual_section & $ini_sect ; Return the Section (in a form to write with) Return $ini_data Else ; Key was specified. If StringInStr($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=") > 0 Then ; Key found, read its Value. $portion = StringSplit($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=", 1) ; Part of Section before Key $ini_sect = $portion[1] ; Part of Section after Key $key_part = $portion[2] $pos = StringInStr($key_part, Chr(13) & Chr(10)) If $pos > 0 Then ; Value for Key in Section $key_part = StringLeft($key_part, $pos - 1) EndIf ; Return the Value Return $key_part Else ; Key not found. If $virtual_report = 1 Then MsgBox(262192, "Read Error", "Key could not be found!", 0) SetError(1, 0, 0) Return "" EndIf EndIf Else ; Section not found, nothing to read. If $virtual_report = 1 Then MsgBox(262192, "Read Error", "Section could not be found!", 0) SetError(1, 0, 0) Return "" EndIf EndFunc ;=> _Ini_Read Func _Ini_Remove($ini_virtual, $virtual_section, $virtual_key = "") ; Remove a Section or Key from an existing INI structured variable. Local $ini_data, $ini_end, $ini_part, $ini_sect, $key_part, $parts, $portion, $pos, $sect $virtual_value = "" $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "remove") = 0 Then SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf $virtual_section = "[" & $virtual_section & "]" $sect = $virtual_section & Chr(13) & Chr(10) If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. $parts = StringSplit($ini_virtual, $sect, 1) ; Start of section to work with until the end of INI structure. $ini_sect = $parts[2] $pos = StringInStr($ini_sect, "[") If $pos > 0 Then ; Start of next section $ini_end = StringMid($ini_sect, $pos) ; Section being worked with $ini_sect = StringLeft($ini_sect, $pos - 1) Else ; No next section $ini_end = "" EndIf $ini_sect = Chr(13) & Chr(10) & $ini_sect If $virtual_key = "" Then ; No Key specified, so return data with Section & its Keys removed. $ini_data = $parts[1] & $ini_end Else ; Key was specified. If StringInStr($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=") > 0 Then ; Key found, remove it and Value. $portion = StringSplit($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=", 1) ; Part of Section before Key $ini_sect = $portion[1] ; Part of Section after Key $key_part = $portion[2] $pos = StringInStr($key_part, Chr(13) & Chr(10)) If $pos > 0 Then ; Start of more Keys in Section $ini_part = StringMid($key_part, $pos) ; Value for Key in Section $key_part = StringLeft($key_part, $pos - 1) Else ; No more Keys in Section $ini_part = "" EndIf If $ini_part = "" Or $ini_part = Chr(13) & Chr(10) Then ; Key & Value were last in Section. If $ini_sect = "" Then ; No prior Keys & Values in Section. $ini_data = $parts[1] & $ini_end Else ; Prior Keys & Values found, so restore Section and return those prior elements. $ini_data = $parts[1] & $virtual_section & $ini_sect & Chr(13) & Chr(10) & $ini_end EndIf Else ; More Data (Key & Value) found later in Section. If $ini_sect = "" Then ; No prior Keys & Values in Section. $ini_data = $parts[1] & $virtual_section & $ini_part & $ini_end Else ; Prior Keys & Values found, so restore Section and return those prior elements. $ini_data = $parts[1] & $virtual_section & $ini_sect & $ini_part & $ini_end EndIf EndIf Else ; Key not found. MsgBox(262192, "Remove Error", "Key could not be found!", 0) SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf EndIf Else ; Section not found, nothing to remove. MsgBox(262192, "Remove Error", "Section could not be found!", 0) SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf ; Return INI structure with Section or Key removed Return $ini_data EndFunc ;=> _Ini_Remove Func _Ini_Rename($ini_virtual, $virtual_section, $virtual_new, $virtual_key = "") ; Rename a Section or Key in an existing INI structured variable. Local $ini_data, $ini_end, $ini_sect, $key_part, $parts, $portion, $pos, $sect $virtual_value = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "rename") = 0 Then SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf $virtual_section = "[" & $virtual_section & "]" $sect = $virtual_section & Chr(13) & Chr(10) If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. $parts = StringSplit($ini_virtual, $sect, 1) ; Start of section to work with until the end of INI structure. $ini_sect = $parts[2] If $virtual_key = "" Then ; No Key specified, so return data with Section renamed. $ini_data = $parts[1] & "[" & $virtual_new & "]" & Chr(13) & Chr(10) & $ini_sect Else ; Key was specified. $pos = StringInStr($ini_sect, Chr(13) & Chr(10) & "[") If $pos > 0 Then ; Start of next section $ini_end = StringMid($ini_sect, $pos) ; Section being worked with $ini_sect = StringLeft($ini_sect, $pos - 1) Else ; No next section $ini_end = "" EndIf $ini_sect = Chr(13) & Chr(10) & $ini_sect If StringInStr($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=") > 0 Then ; Key found, rename it. $portion = StringSplit($ini_sect, Chr(13) & Chr(10) & $virtual_key & "=", 1) ; Part of Section before Key $ini_sect = $portion[1] ; Part of Section after Key $key_part = $portion[2] ; Reassemble INI structure from part before Section, Section Name, part before Key, ; plus Key Renamed, Value for Key, Remaining part of Section &/or INI structure. $ini_data = $parts[1] & $virtual_section & $ini_sect & Chr(13) & Chr(10) & $virtual_new & "=" & $key_part & $ini_end Else ; Key not found, nothing to rename. MsgBox(262192, "Rename Error", "Key could not be found!", 0) SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf EndIf Else ; Section not found, nothing to rename. MsgBox(262192, "Rename Error", "Section could not be found!", 0) SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf ; Return INI structure with Section or Key renamed Return $ini_data EndFunc ;=> _Ini_Rename Func _Ini_Save($ini_virtual, $ini_fle) ; Save from an existing INI structured variable into an INI file. Local $file $file = FileOpen($ini_fle, 2) If $file = -1 Then MsgBox(262192, "Save Error", "The specified file could not be opened for writing to!", 0) SetError(1, 0, 0) Return EndIf FileWrite($file, $ini_virtual) FileClose($file) EndFunc ;=> _Ini_Save Func _Ini_SectionNames($ini_virtual) ; List all the Sections in an existing INI structured variable as a pipe delimited string. Local $ini_data, $ini_part, $pos, $parts ; Set all unused parameters to nothing so the Test doesn't fail for wrong reasons. $virtual_section = "" $virtual_key = "" $virtual_value = "" $virtual_new = "" If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "sections") = 0 Then SetError(1, 0, 0) ; Return INI structure without any changes Return "" EndIf $ini_data = "" ; Split content at every line. $parts = StringSplit($ini_virtual, Chr(13) & Chr(10), 1) For $pos = 1 To $parts[0] $ini_part = $parts[$pos] ; If line is encapsulated in square brackets, then it is a Section name. If StringLeft($ini_part, 1) = "[" And StringRight($ini_part, 1) = "]" Then ; Strip out brackets and add a pipe delimeter. $ini_part = StringTrimLeft($ini_part, 1) $ini_part = StringTrimRight($ini_part, 1) $ini_data &= $ini_part & "|" EndIf Next ; Remove trailing pipe if exist (if result is not blank). $ini_data = StringTrimRight($ini_data, 1) ; Return Sections found. Return $ini_data EndFunc ;=> _Ini_SectionNames Func _Ini_Show($ini_virtual, $virtual_section = "", $virtual_title = "") ; Show the content of an INI structured variable. Local $ini_array, $ini_sect, $sect If $virtual_section = "" Then ; Show full INI cotent If StringLen($ini_virtual) < 500 Then MsgBox(262192, "INI Content " & $virtual_title, $ini_virtual, 0) $ini_array = StringSplit($ini_virtual, Chr(13) & Chr(10), 1) Else ; Show Section content only $sect = "[" & $virtual_section & "]" If StringInStr($ini_virtual, $sect) > 0 Then $ini_sect = StringSplit($ini_virtual, $sect, 1) $ini_sect = $ini_sect[2] $ini_sect = StringSplit($ini_sect, "[", 1) $ini_sect = $sect & $ini_sect[1] If StringLen($ini_sect) < 500 Then MsgBox(262192, "INI Content " & $virtual_title, $ini_sect, 0) $ini_array = StringSplit($ini_sect, Chr(13) & Chr(10), 1) Else MsgBox(262192, "Parameter Error", "The specified Section wasn't found!", 0) SetError(1, 0, 0) Return EndIf EndIf _ArrayDisplay($ini_array, $virtual_title) EndFunc ;=> _Ini_Show Func _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, $virtual_job) ; Test for illegal characters in a Section or Key name or the Value, in an existing INI structured variable. If $ini_virtual = "" And $virtual_job <> "create" Then MsgBox(262192, "Parameter Error", "INI structured variable does not exist (not opened or created)!", 0) Return 0 ElseIf (StringInStr($ini_virtual, "[") < 1 Or StringInStr($ini_virtual, "]") < 1) And $virtual_job <> "create" Then MsgBox(262192, "INI Error", "No valid INI structure found (use Create or Open first)!", 0) Return 0 ElseIf $virtual_job = "add" And ($virtual_section = "" Or $virtual_key = "") Then MsgBox(262192, "Parameter Error", "A required parameter for Add/Update is blank!", 0) Return 0 ElseIf $virtual_job = "create" And ($virtual_section = "" Or $virtual_key = "") Then MsgBox(262192, "Parameter Error", "A required parameter for Create is blank!", 0) Return 0 ElseIf $virtual_job = "read" And $virtual_section = "" Then MsgBox(262192, "Parameter Error", "A required parameter for Read is blank!", 0) Return 0 ElseIf $virtual_job = "remove" And $virtual_section = "" Then MsgBox(262192, "Parameter Error", "A required parameter for Remove is blank!", 0) Return 0 ElseIf $virtual_job = "rename" And ($virtual_section = "" Or $virtual_new = "") Then MsgBox(262192, "Parameter Error", "A required parameter for Rename is blank!", 0) Return 0 ElseIf $virtual_job = "write" And $virtual_new = "" Then MsgBox(262192, "Parameter Error", "The required data for Write is blank!", 0) Return 0 ElseIf $virtual_job = "write" And $virtual_section = "" And (StringInStr($virtual_new, "[") < 1 Or StringInStr($virtual_new, "]") < 1) Then MsgBox(262192, "Section Error", "The required format for Write is incorrect!", 0) Return 0 ElseIf $virtual_job = "sections" Then Return 1 ElseIf $virtual_job = "keys" And $virtual_section = "" Then MsgBox(262192, "Parameter Error", "The required data for Keys is blank!", 0) Return 0 Else If StringInStr($virtual_section & $virtual_key & $virtual_value, "[") > 0 Or StringInStr($virtual_section & $virtual_key & $virtual_value, "]") > 0 Then MsgBox(262192, "Illegal Character Error", "A square bracket '[ or ]' was found in a parameter!", 0) Return 0 ElseIf StringInStr($virtual_section & $virtual_key & $virtual_value, Chr(13)) > 0 Or StringInStr($virtual_section & $virtual_key & $virtual_value, Chr(10)) > 0 Then MsgBox(262192, "Illegal Character Error", "A carriage return or line feed was found in a parameter!", 0) Return 0 ElseIf StringInStr($virtual_section, "|") > 0 Then MsgBox(262192, "Illegal Character Error", "A pipe '|' was found in the Section parameter!", 0) Return 0 ElseIf StringInStr($virtual_key, "=") > 0 Then MsgBox(262192, "Illegal Character Error", "An equals sign '=' was found in the Key parameter!", 0) Return 0 Else Return 1 EndIf EndIf EndFunc ;=> _Ini_Test Func _Ini_WriteSection($ini_virtual, $virtual_data, $virtual_section = "", $virtual_replace = 0) Local $ini_data, $ini_end, $ini_sect, $parts, $pos, $sect $virtual_key = "" $virtual_value = "" $virtual_new = $virtual_data If _Ini_Test($ini_virtual, $virtual_section, $virtual_key, $virtual_value, $virtual_new, "write") = 0 Then SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf If StringLeft($virtual_data, 1) = "[" Then ; Section name seems to exist. $pos = StringInStr($virtual_data, "]") If $pos > 0 Then ; Section name should exist. Data should now start with line feed. $ini_data = StringMid($virtual_data, $pos + 1) ; Section name doesn't have line feed at end. If $virtual_section = "" Then $virtual_section = StringLeft($virtual_data, $pos) Else $virtual_section = "[" & $virtual_section & "]" EndIf Else ; Section name doesn't exist. SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf ;MsgBox(262192, "$virtual_section Check", $virtual_section, 0) $sect = $virtual_section & Chr(13) & Chr(10) Else ; Section name structure not found. SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf If $virtual_section = "[]" Then ; Section name is blank. SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual Else If StringInStr($ini_virtual, $sect) > 0 Then ; Section found. There is no checking of individual keys. If $virtual_replace = 1 Then ; Simply replace the whole section. $parts = StringSplit($ini_virtual, $sect, 1) ; Start of section to work with until the end of INI structure. $ini_sect = $parts[2] $pos = StringInStr($ini_sect, Chr(13) & Chr(10) & "[") If $pos > 0 Then ; Start of next section $ini_end = StringMid($ini_sect, $pos) ; Section being worked with, but will be replaced. $ini_sect = StringLeft($ini_sect, $pos - 1) Else ; No next section $ini_end = "" EndIf ; Section is to be replaced, so $ini_sect = $ini_data $ini_virtual = $parts[1] & $virtual_section & $ini_sect & $ini_end Else ; Section name exists and replace is not specified. SetError(1, 0, 0) ; Return INI structure without any changes Return $ini_virtual EndIf Else ; Section not found, so add as new. $ini_virtual = $ini_virtual & $virtual_section & $ini_data EndIf EndIf Return $ini_virtual EndFunc ;=> _Ini_WriteSection Func _Ini_CopySection($ini_virtual, $virtual_section, $virtual_newsect) ; Copy a Section to another Section (or Create one) in an existing INI structured variable. EndFunc ;=> _Ini_CopySection