IniWrite issue Topic is solved

Get help with using AutoHotkey and its commands and hotkeys

IniWrite issue

13 Jun 2016, 14:37


I was hoping if someone could provide some feedback on using IniWrite.

A While back I used this as a reference: ... a-INI.html

Following this I was able to use IniWrite and IniRead.

But recently I tried using it again and I am perplexed that I am not able get IniWrite to "write" to the *.ini file.

I've simplified the code with the following and the only thing I can think of is making an incorrect filename path. But I've checked that a number of times and can't see where I might be going wrong.

This is the script from the AHK file I am using:

Code: Select all




And here is the pre-setup ini file I am using. I added the "Empty" because the above link says leaving blank would cause some issues, although I tried anyways but still can't get any "writes" to that file:

Code: Select all

Any feedback/help is appreciated. Thanks
User avatar
Capn Odin
Posts: 1308
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: IniWrite issue

13 Jun 2016, 15:49

I am not sure if this is your problem, but try changing the encoding of your script to UTF-16 LE BOM.
Please excuse my spelling I am dyslexic.

Re: IniWrite issue  Topic is solved

13 Jun 2016, 17:09

Although this didn't work thanks for the suggestion anyway Capn Odin.
Posts: 20
Joined: 15 Apr 2016, 06:26

Re: IniWrite issue

14 Jun 2016, 01:57

Example from one of my scripts:

Code: Select all

IniWrite, %email% , h:\script\watgedaan.INI, %date%, %cnummer%  
as you see, all the vars need %'s arround them. Maybe this helps?
Posts: 7057
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: IniWrite issue

14 Jun 2016, 03:02

What's the result of this?

Code: Select all

r := DllCall("WritePrivateProfileString", "str", "People", "str", "Name"
             , "str", "Tim", "str", "C:\Users\Me\Documents\TestAHK\Friends.ini")
MsgBox % Clipboard := "Result: " r "`nLastError: " A_LastError
It should have the same effect as IniWrite (which just calls this function internally), but will give an error code indicating the reason for failure, if it fails.

Re: IniWrite issue

14 Jun 2016, 08:36

Thanks for the suggestion florisvos but that didn't seem to do anything.


I get the message:

Result: 0
LastError: 3

I'm assuming 3 means the third argument which is the structure element of "People".

I checked the ini file...seems to be formated correctly I'm not sure.
Posts: 92
Joined: 28 Mar 2016, 07:59

Re: IniWrite issue

14 Jun 2016, 11:09

Just to be sure, your ini is..


Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: IniWrite issue

14 Jun 2016, 11:48

The original script works on my system (I had to change the path of course - I changed it to C:\Temp\Friends.ini.

My suspicion is that your C:\Users\Me\Documents\TestAHK\Friends.ini file has been set to Read Only, or some other application (maybe anti-virus, or possibly another AHK script?) is preventing you from modifying the file.

Re: IniWrite issue

14 Jun 2016, 14:24

So Shadowpheonixs suspician got me in the right direction.

I checked the file read/write attributes and it didn't have it set as read only.

I checked for other AHK processes going on with task manager and it didn't show anything that might suggest preventing working with that file.

So I just tried putting both the ini and ahk files in C:/temp directory and ran it from there.

In that case it works.

So then I put the ahk back in the original folder from where I want it to work from but keep the ini file in the temp directory.

And that works too.

So since I don't mind having the ini file in another directory and I can keep my ahk file where I want it, I'm not going to pursue the matter any further as to why it won't read the ini file where it originally was.

I really appreciate the feedback and time you guys have given. So thanks alot in helping me get it working to do what I need.

Although I don't need to take the "issue" any further to find out why the ini has to be in another directory, I'm willing to check back here and try suggestions for those who want to know out of curiosities sake.

Thanks again
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: IniWrite issue

14 Jun 2016, 18:05

If you are happy with the INI somewhere else, then you are all set. If you decide you do want the INI in the C:\Users\Me\Documents\TestAHK folder, then LockHunter might be a good next step.

Re: IniWrite issue

15 Jun 2016, 06:06

Thanks Shadowpheonix....yeah, I'm cool with how it is...but I was curious so I ran LunterHunter anyways and it says the file ( how I originally had it setup ) is not locked nor is the folder that it's sitting in.

But that's cool...I never knew about this tool, so thanks for the reference. I'm sure it will come in handy sometime.

Re: IniWrite issue

15 Jun 2016, 06:08

* LockHunter >'t had morning coffee yet.
Posts: 7057
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: IniWrite issue

16 Jun 2016, 03:32

Guest wrote:I'm assuming 3 means the third argument which is the structure element of "People".
No. It means "that directory doesn't exist!"
3 (0x3)
The system cannot find the path specified.
Source: System Error Codes (0-499) (Windows)
It is the same error that I get if I run the code, unless I create the directory C:\Users\Me\Documents\TestAHK first.

Re: IniWrite issue

17 Jun 2016, 08:31

Thanks lexikos,

Thats what it was. The directory wasn't specificed correctly in my code.

Or at least that's what I think it must have been.

I changed my script to refer back to the original location and put my ini file back there and now it works.

So I must of had some extra space, wrong spelling or something in the directory path of my script.

Re: IniWrite issue

21 Jun 2016, 09:38


I started working on a new project and the same problems started to happen.

Upon doing a little testing it appears I didn't have the folder/file path set wrong

Setting up a new ini file for my project there is no problem writing and making changes to the ini file.

But the ahk script file that reads from it wasn't able to do so initially.

So I made a copy of that ini file and put it in C:/My_Temp.

Then it was able to read the ini file.

So then I changed the reference to the original ini location and it is then able to read.

It's almost like theres some kind of flag/initialization or something not happening with the ahk or ini file itself.

Just thought I would write about it in case someone else happens to at some point have the same problem.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], littlegandhi1199, RyConnMD, tatagi and 29 guests