Search code examples
delphidelphi-6

Delphi CommonAppDataFolder seems un-writeable


I get the common app data folder to store my application related files. Eg log files and ini config files. I use the following code:

const
    CSIDL_COMMON_APPDATA     = $0023;

function TSpecialFolders.GetSpecialFolder(
  const ASpecialFolderID: Integer): string;
var
   vSFolder :  pItemIDList;
  vSpecialPath : array[0..MAX_PATH] of Char;
begin
  SHGetSpecialFolderLocation(0, ASpecialFolderID, vSFolder);
  SHGetPathFromIDList(vSFolder, vSpecialPath);
  Result := vSpecialPath;
end;

function TSpecialFolders.GetCommonDocumentsFolder: string;
begin
  result := GetSpecialFolder(  CSIDL_COMMON_DOCUMENTS );
end;     

This works fine on my Windows 7 box and allows my app to write folders and files.

On a customers PC (I think its an older version of windows, because the screen shot has the word "start" on the start button) my app is unable to write files into that path.

On my PC the returned path is:

C:\ProgramData\

with me adding extra folders like so:

mycompany\myapp\logs\

mycompany\myapp\db\

with text files being saved in those folders.

On my customer's PC the function returns:

C:\Documents and Settings\All Users\Application Data

I am unable to write text files into the directory structure there.

Is there a better function I should be using, or a better common file folder?


Edit for SilverWarrior

these are the special folders on my customer's PC.

AppDataFolder : C:\Documents and Settings\Admin\Application Data CommonAppDataFolder : C:\Documents and Settings\All Users\Application Data CommonDocumentsFolder : C:\Documents and Settings\All Users\Documents LocalAppDataFolder : C:\Documents and Settings\Admin\Local Settings\Application Data MyDocumentsFolder : C:\Documents and Settings\Admin\My Documents

The LocalAppDataFolder has "Admin" in the path suggesting that admin rights would be needed. Is that right?


Solution

  • Well, armed with info from here and a double-hop remote desktop connection to my customer's pc I went in prepared to do battle with the Windows permissions system - only to find that the problem was due to the application's ini file was set to read only.

    Clickity click. Problem solved.

    All comments about the common app data folder being restricted may still apply as the customer is running his account as administrator on XP SP3.

    Thank you for your help.