DagSa

No write previlege to INI file in %appdata%

16 posts in this topic

I have some problem to make my ini-file work properly. Purpose is to install program at windows 7 - 10 but think it work at XP also.
 I have included a fragment of code, but all my errors are there. It should be run by user privilege.
The test code point out what is not working:
Code is create a directory in %appdata%, and create a ini-file if not there. (This write of file work!)
When change the settings only one of the two parameters are changed. One value should be changed (don't work), and the other should be added (work!). Editing manually by notepad does not allow to save it.  I want the code to be able to change everything in ini-file.

1. First of all, the ini-file is not writeable by user when look at file properties and also directory properties. Any way to change this?

2. Is %appdata% wrong directory? I want all user to have access to the settings but its enough if only by control of the program.

It make me crazy its writeable sometimes, and sometimes not. Any ideas?
/Dag

AppData_INI-test.au3

Share this post


Link to post
Share on other sites



I Think JohnOne means @AppDataDir (User Folder), @AppDataCommonDir is a System folder.

1 person likes this

Share this post


Link to post
Share on other sites

DagSa appears to be using @AppDataCommonDir in his script, so probably confused it as %AppData%.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I use @AppDataCommonDir because its for all users.
%programdata% in Windows:
XP: C:\Documents and Settings\All Users\Application Data
Vista->10:  C:\ProgramData

@AppDataDir is for current user, but it have same properties for write/change as @AppDataCommonDir.
%appdata% in Windows:
XP: C:\Documents and Settings\All Users\Application Data
Vista->10: C:\Users\ <user name>\AppData\Roaming

It behave exactly the same in win7. Possible to write, but not overwrite or change.
Its essential to be able to read and write to a INI file in my opinion.
Isnt one of this folders the right one?
Any way to change the properties/privilege for "my" folder where the INI file is located?

Edited by DagSa
clearyfing

Share this post


Link to post
Share on other sites

As mentioned in @AppDataCommonDir is a System folder, unless you change the folder/file permissions using something like cacls or subinacl, you won't be able to write to a file within that directory unless you're a member of the local Administrators group.

Share this post


Link to post
Share on other sites

#10 ·  Posted

1 minute ago, jguinch said:

You need rigths. Try to add #RequireAdmin at the top of your code

This program should be used by a simple user, and program have some settings to be done like select a printer and save the setting, save the windows location so it could start at same place next time. You don't need Admin privilege for that.
Of course some other settings could be saved at time of installation with Admin rights, but not for the daily use.
Possible to give the software privilege to "my" settings?

Share this post


Link to post
Share on other sites

#11 ·  Posted

19 minutes ago, JohnOne said:

@DocumentsCommonDir

Tested, with same result. But progress
Folder is hide, so that's good. In win7: C:\Users\Public\Documents\_TEST

But the privilege is different for this folder and should not limit to read/write/change in INI file.
But the code don't work, so it must be something in code not working.
Possible to change and save by notepad.

Code don't change the phonenumber in INI file.

Share this post


Link to post
Share on other sites

#12 ·  Posted

@DagSa - All folders for %Public% or %AllUsersProfile% are system folders, unless you change the permissions on the folders standard users cannot save to these folders natively.

Share this post


Link to post
Share on other sites

#14 ·  Posted

I found errors in code, because it was cutted out from other context. It works after some changes
I have a installer for the exe so its covered.
I test whats work and will be back with more info, thanks for support!
/Dag

Share this post


Link to post
Share on other sites

#16 ·  Posted

@JohnOne - Apologies, I stand corrected, the Public Documents has Interactive Modify Permissions which allows writing to the folder.

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

    • l3ill
      By l3ill
      Hi All,
      Here is a little GUI I built a while back to learn how to use INI files to store information ( variables ) between opening and closing certain programs.
      I just recently pulled it back out and cleaned it up and debugged it, if you find any bugs please kill them.
      The FTP connection part was just so it would have purpose... 
      To cut down on clutter there are no labels, hover mouse over to see what things are.
      cya,
      Bill
    • akira2891
      By akira2891
      Hi i have problem with reading data from INI file.
      So i need when i put in search field "Test" to get in listbox all results under number 1= with "Test" in name and so my list need to look like this
      [5018] Test name 2 [5218] Test name 1 [5458] Test name and when i click on item from list that he appears on $hNameInput
      Look on image http://prntscr.com/83i7a6
      this is my ini file
      [5018] 0=test1 1=Test name 2 2=0 3=1 [5218] 0=test1 1=Test name 1 2=0 3=1 [5458] 0=test1 1=Test name 2=0 3=1 [5468] 0=test1 1=Name no 1 2=0 3=1 [5345] 0=test1 1=Name no 2 2=0 3=1 And here is autoit code
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=C:\Users\Mario\Documents\renamer.kxf $hGUI = GUICreate("Form1", 684, 364, 607, 439) GUICtrlCreateGroup(" Search ", 8, 16, 342, 297) GUICtrlCreateLabel("Search for text", 22, 40, 73, 17) $hSearchInput = GUICtrlCreateInput("", 23, 60, 185, 21) $hFinddAllButton = GUICtrlCreateButton("Find All", 222, 58, 75, 25) GUICtrlCreateLabel("Found Items ( click to edit )", 22, 102, 131, 17) $hList = GUICtrlCreateList("", 22, 120, 313, 175) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup(" Edit Item", 355, 16, 321, 137) GUICtrlCreateLabel("Name", 372, 40, 32, 17) $hNameInput = GUICtrlCreateInput("", 371, 60, 289, 21) $hSaveButton = GUICtrlCreateButton("Save", 587, 112, 75, 25) GUICtrlCreateLabel("Item ID", 372, 95, 38, 17) $hItemID = GUICtrlCreateInput("", 369, 112, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_READONLY)) GUICtrlCreateGroup("", -99, -99, 1, 1) $hOpenIniButton = GUICtrlCreateButton("Open INI for Edit", 8, 328, 105, 25) $hWriteIniButton = GUICtrlCreateButton("Write Modified INI", 123, 328, 105, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $file While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hOpenIniButton __openINI() Case $hFinddAllButton Local $iFileExists = FileExists($file) If Not $iFileExists Then MsgBox(48, "Error", "test.ini not found!") EndIf Local $aArray = IniReadSection($file, "5018") If Not @error Then For $i = 1 To $aArray[0][0] GUICtrlSetData($hList, $aArray[$i][1] & @CRLF) Next EndIf EndSwitch WEnd ; open ini Func __openINI() Global $file = FileOpenDialog("Open INI for edit", "", "INI files (*.ini)") If FileExists($file) Then $sFile = FileOpen($file) If @error Then MsgBox(48, "Error", "Error = " & @error & ", Extended = " & @extended) Else GUICtrlSetState($hOpenIniButton, $GUI_DISABLE) EndIf Else MsgBox(48, "Error", "Error = " & @error & ", Extended = " & @extended) EndIf EndFunc  
    • meows
      By meows
      Func Button2Click() ;==> SonoLvl2 ******************************************************* SoundPlay(@ScriptDir & "\schoolbell.wav", 1) Local $Test2 = IniRead(@ScriptDir & "\runer.ini", "Levels", "LComplete1", "Default Value") If $Test2 = 1 Then ; $updatepid = RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_SHOWDEFAULT) Else MsgBox(4096, "", "You did not complete Lesson1") EndIf ;MsgBox($MB_SYSTEMMODAL, "Bug Report Environment", _DebugBugReportEnv()) IniWrite(@ScriptDir & "\runer.ini", "Levels", "LComplete2", "2") EndFunc ;==>Button2Click I have tried PID checks and updatepid per the help file and they just didn't work out. and usually caused errors. Then (not included I tried making a separate function to write to a INI file. that was a lesson in frustration and defeat. It worked.. just the same as the code in the function now. as soon as you click the button and the runwait line starts the ini gets updated. The file can only be written to after runwait is running is closed. Also tried the ProcessWait, ProcessWaitClose,  ShellExecute, ShellExecuteWait
      Then in desperation I tried a Debug i read about
      Func Button2Click() ;==> SonoLvl2 ******************************************************* $__iLineNumber=162 & ' - SoundPlay(@ScriptDir & "\schoolbell.wav", 1)•' SoundPlay(@ScriptDir & "\schoolbell.wav", 1) $__iLineNumber=163 & ' - Local $Test2 = IniRead(@ScriptDir & "\runer.ini", "Levels", ...•' Local $Test2 = IniRead(@ScriptDir & "\runer.ini", "Levels", "LComplete1", "Default Value") $__iLineNumber=164 & ' - If $Test2 = 1 Then•' If $Test2 = 1 Then $__iLineNumber=165 & ' - $updatepid = RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", ...•' $updatepid = RunWait(@ScriptDir & "\SonoLvl2\SonoLvl2_.exe", "", @SW_SHOWDEFAULT) Else $__iLineNumber=167 & ' - MsgBox(4096, "", "You did not complete Lesson1")•' MsgBox(4096, "", "You did not complete Lesson1") EndIf ;MsgBox($MB_SYSTEMMODAL, "Bug Report Environment", _DebugBugReportEnv()) $__iLineNumber=173 & ' - IniWrite(@ScriptDir & "\runer.ini", "Levels", "LComplete2", ...•' IniWrite(@ScriptDir & "\runer.ini", "Levels", "LComplete2", "2") EndFunc ;==>Button2Click unfortunately I was not smart enough to get it to work for me. What I wanted was a Debugger that explains what each line does and why. Then I figured out that isn't happening.
    • lgvlgv
      By lgvlgv
      Hi all!
      Im trying to execute a program that are specified in a ini file like this but shellexecute ignore the @windowsdir or any @variable i put in, what im i doing wrong?


      ; Ini file [Utforskaren] exe= explorer.exe arg= , C: wrk= @WindowsDir ico= @WindowsDir & "\explorer.exe" dsc= Utforskaren
      the execute is from an array like this

      [3]|explorer.exe|, C:|@WindowsDir|@WindowsDir & "\explorer.exe"|Utforskaren



      ShellExecute($aIcon[$iIconIndex][0], $aIcon[$iIconIndex][1], $aIcon[$iIconIndex][2]) ConsoleWrite("! Consolewrite ->Shellexecute: " & $aIcon[$iIconIndex][0] &" | "& $aIcon[$iIconIndex][1] &" | "& $aIcon[$iIconIndex][2] & @CRLF)

      and result is this

      ! Consolewrite ->Shellexecute: explorer.exe | , C: | @WindowsDir