VollachR Posted June 6, 2018 Posted June 6, 2018 Hi, I'm creating a tool to edit some ini files that belong to a program I'm working on... Basically everything work fine except I can't find a way to check if the if the WriteIniSection operation was successful... For Example, let's say the INI file is by mistake or some other reason Read Only, or the user don't have the right permission to write to the file or the folder it's in... Right now, in such a case The INI file, as expected, won't get updated, but I when I perform an if error or if not error checks I always get the msgbox for the if not error. Here's the relevant code part: IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Conversion", $aConversion, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "AIO", $aAIO, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Data", $aData, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Redist", $aRedist, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Split", $aSplit, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Autorun", $aAutorun, 1) If Not @error Then MsgBox($MB_ICONINFORMATION, "Success", "Settings.ini Saved Successfully") Else If @error Then MsgBox($MB_ICONERROR, "Failure", "Settings.ini Could Not Be Saved!" & @CRLF & @CRLF & "Please Check If The File Is ReadOnly And That You Have Permission To Change It Or Its Location") EndIf EndIf How can I perform a check to see if the ini file was written to successfully? Thanks. Ron VollachMicrosoft Certified Professional (MCP)Creator of Ultimate Conversion Compressor (UCC)UCC Wikia
Subz Posted June 6, 2018 Posted June 6, 2018 (edited) Check if the return value equals 0 Local $hIniWrite $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Conversion", $aConversion, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("Conversion") $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "AIO", $aAIO, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("AIO") $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Data", $aData, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("Data") $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Redist", $aRedist, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("Redist") $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Split", $aSplit, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("Split") $hIniWrite = IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Autorun", $aAutorun, 1) If $hIniWrite = 0 Or @Error Then _IniWriteError("Autorun") Func _IniWriteError($sSection = "") MsgBox(4096, "Error Writing " & $sSection, "Error writing to Ini File or data format is invalid") Exit EndFunc Edited June 6, 2018 by Subz Updated Script VollachR 1
VollachR Posted June 6, 2018 Author Posted June 6, 2018 Thank you, that worked perfectly. Ron VollachMicrosoft Certified Professional (MCP)Creator of Ultimate Conversion Compressor (UCC)UCC Wikia
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now