Recent

Author Topic: Writing files in the c:\programs\myapp folder  (Read 4515 times)

Martin V

  • Full Member
  • ***
  • Posts: 139
Writing files in the c:\programs\myapp folder
« on: November 29, 2011, 07:28:40 pm »
Since Windows Vista, programs which are stored in the default Programs folder (normally c:\programs) are no more allowed to write files in this folder. To beware compatibility with older programs, Vista generates a new application data folder with full read/write access. If a file exists in this folder, this file gets read and written,  even though the programmer writes a file to 'c:\programs\myapp\sample.txt', and only if it does not exist, the 'original' file in the c:\programs\myapp folder gets read.

I have ported now my application from another Pascal IDE (WDsibyl) to Lazarus. Now this Vista-built in mechanism does not work anymore and I get errors with missing write access in the c:\programs\myapp folder. WDsibyl definitively does not have any special mechanism for writing in the separate application data folder, so it seems that Lazarus system.assign and system.rewrite is more hard-coded so the Vista mechnism is not active here.

This is not pretty because the user always gets file write errors, and I do not want to change the file structure of my program, because it works fine on other OS.

Any idea how to assign/rewrite a file to get this mechanism work again?

circular

  • Hero Member
  • *****
  • Posts: 4383
    • Personal webpage
Re: Writing files in the c:\programs\myapp folder
« Reply #1 on: November 29, 2011, 07:34:09 pm »
It's strange. Anyway you can use :
Code: [Select]
CreateDir(GetAppConfigDir(False));
  ConfigFile := GetAppConfigFile(False,False);
Conscience is the debugger of the mind

Bart

  • Hero Member
  • *****
  • Posts: 5510
    • Bart en Mariska's Webstek
Re: Writing files in the c:\programs\myapp folder
« Reply #2 on: November 29, 2011, 10:06:49 pm »
Any idea how to assign/rewrite a file to get this mechanism work again?

You are looking at this the wrong way around.
Since Windows95 the MS guidelines say you are not supposed to store user data in that place, but use %LOCALAPPDATA% or similar (or use the registry when applicable, but that is not cross-platform if you mind about that).
At some point MS might stop supporting this virtual storage space, and then your app won't work anymore.

GetAppConfigDir() uses exactly this approach (for each OS fpc supports).

Bart

 

TinyPortal © 2005-2018