Sign in to follow this  
Followers 0
BitByteBit

IniWrite in vista

7 posts in this topic

#1 ·  Posted (edited)

I'm trying to write to an existing .ini file in Program Files on Vista, it doesn't write to the file and I'm not sure why not.

Any pointers?

Edit:

I needed to have full access rights to the folder, any way to automate this? Or does my .exe need to run with admin rights?

Edited by BitByteBit

Share this post


Link to post
Share on other sites



BitByteBit,

Vista blocks you from writing in the "C:\Program Files" folder - security don't you know! ;) You will probably find your file somewhere in "C:\Users\user_name\AppData".

I use this code to get round the problem:

; Determine location for ini file
If StringInStr(@ScriptDir, "Program Files") Then
    ; If app in C:\Program Files need to save elsewhere
    If Not FileExists(@AppDataDir & "\App_Name") Then DirCreate(@AppDataDir & "\App_Name")
    $sAppData_Path = @AppDataDir & "\App_Name"
Else
    ; Can use app folder
    $sAppData_Path = @ScriptDir
EndIf

Then I at least know where my file will be and Vista does not get in the way. :) You can easily modify it to your own needs.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Melba23 to the rescue!

Great, now I know where my files went!

However,I use an installer to put the .ini file in Program Files and need to edit it through autoit.

Are you telling me that I have to use this work around?

Check for vista, if it is then always read/write that file?!

Surely I can change the permissions on the folder? I've been told that if I run the program as Admin, since that has write rights then it will in fact write the .ini, is the solution not here? IsAdmin()?

There must be hope!

Edited by BitByteBit

Share this post


Link to post
Share on other sites

BitByteBit,

Vista uses a clever trick called Virtualisation to store the file elsewhere while fooling file managers. Google offered this:

Virtualization Example

For example, take a legacy software application that attempts to write to a configuration INI file located in:

C:\Program Files\<application>\Setup.ini

Windows Vista automatically detects that you do not have permission to save to that location. Windows Vista then copies the file (if it already exists) to:

C:\Users\<your_account>\AppData\Local\VirtualStore\Program Files\<application>\Setup.ini

Windows Vista then allows the write operation to succeed at the new file in the VirtualStore folder. Subsequent read and write operations for that file will always use the file copy located in the VirtualStore folder. However, the application will continue to believe that it is accessing the Program Files directory.

So as I read this, you should be able to edit the ini file directly through AutoIt - it is just that you will not be editing the actual file, just the copy.

That is a far as my knowledge goes - I bow out here. :) Perhaps a Vista guru can go deeper. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

After more thought and debate I came up with this:

$Os = @OSVersion
if $Os = "WIN_VISTA" then
FileCopy(@ProgramFilesDir & "\FarmShark\FV.ini", @MyDocumentsDir& "\FarmShark\FV.ini",0+8)
Global $Location = @MyDocumentsDir& "\FarmShark\FV.ini"
;MsgBox(0,"",$Location & "1")
Else
Global $Location = @ProgramFilesDir & "\FarmShark\FV.ini"
;MsgBox(0,"",$Location)
EndIf

Thanks Melba, just the work around I needed. (+)

@OSVersion returns "WIN_VISTA" if your running windows 7, is this fixed in the beta by chance?

@AdmiralAlkex

Damn, should of seen that earlier would of saved me some hassle! Thanks though! (+)

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
Sign in to follow this  
Followers 0