BitByteBit Posted November 25, 2009 Share Posted November 25, 2009 (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 November 25, 2009 by BitByteBit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2009 Moderators Share Posted November 25, 2009 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 EndIfThen 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BitByteBit Posted November 25, 2009 Author Share Posted November 25, 2009 (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 November 25, 2009 by BitByteBit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2009 Moderators Share Posted November 25, 2009 BitByteBit,Vista uses a clever trick called Virtualisation to store the file elsewhere while fooling file managers. Google offered this:Virtualization ExampleFor example, take a legacy software application that attempts to write to a configuration INI file located in: C:\Program Files\<application>\Setup.iniWindows 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.iniWindows 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted November 25, 2009 Share Posted November 25, 2009 Try to run your script as an administrator #RequireAdmin ;your script under here .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
BitByteBit Posted November 25, 2009 Author Share Posted November 25, 2009 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! (+) Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted November 25, 2009 Share Posted November 25, 2009 @OSVersion returns "WIN_VISTA" if your running windows 7, is this fixed in the beta by chance?Yes it was fixed months ago. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
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