Jump to content

IniDelete returning success no key being deleted

Recommended Posts

Dear All,

I'm trying to modify an .ini file created by another application.

Problem with this file is that there is no [SECTION]


all the way down.

So in order to attempt to change a value of a key I used IniWrite leaving the "section" parameter blank ("").

What AutoIt3 actually did is create a new key at the bottom of the file:


leaving the original key unmodified.  :'(

Then by trying to be clever I made it even worse.  :sweating:

I thought I could just try deleting the original key

IniDelete($filename , "", "this")

which didn't even touch the file at all!  :blink:

I checked the file versions, nothing modified.

But what's even more confusing is that the IniDelete function returns 1 (success)

I'm really confused.  :(

Thanks in advance for help!


Link to post
Share on other sites

I think the function only returns  0 if the INI file does not exist or if the file is read-only (yep help file says so), so as long as these criteria were met, it's a success.

You could try to write a section at the top of the file using filewriteline or similar, hopefully the parent application will ignore it and you can use ini functions.

You could also try reading the file to an array and search for the key you want to update, change it then write the file back.

Link to post
Share on other sites

Just tested and it worked fine for me

Local $sFileName = @ScriptDir & "\Filename.ini"
IniWrite($sFileName, "", "This", "That")
MsgBox(64, "IniRead", IniRead($sFileName, "", "This", "Something Else"))
IniDelete($sFileName, "", "This")
MsgBox(64, "IniRead", IniRead($sFileName, "", "This", "Something Else"))
IniDelete($sFileName, "")

As benners pointed out you could just insert a section name to the top of the file and then use the standard ini functions to read for example:

Local $sFileRead = FileRead($sFileName)
Local $hFileName = FileOpen($sFileName, 2)
FileWrite($hFileName, "[Section]" & @CRLF & $sFileRead)


Link to post
Share on other sites

Sup ppl.

I think what the problem is I'm having here is that the INI file is not controlled by me.

I'm taking a pre-configured INI file set up in a no-headings way.  I don't really have control over it.

So what Subz and Prodigy both advice is correct, but I am trying to modify existing keys that might already be in the untidy file.

This seemingly is not what IniWrite and IniDelete have been designed for seemingly.

Prodigy thanks for the heads up on what the return result really meant though.  It's good to know.

By the way Prodigy if you create a dummy section it works ok but leaves the original untidy one unchanged which is what I am trying not to have.



Edited by Pablos544
correct Key to Section
Link to post
Share on other sites

If it does not have a section then it is not really an ini file.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to post
Share on other sites

Are you sure you tried the examples Subz gave ... substituting file names etc where applicable?

If it works for him, it should for you, unless you need Admin Rights ... but then you created a section, so it appears that Admin is not needed.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...