Hello

Hello

I am using this function:

function GetAppDataLocalFolderPath: string;
const
SHGFP_TYPE_CURRENT = 0;
var
path: array [0..MAX_PATH] of char;
begin
if SUCCEEDED(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, SHGFP_TYPE_CURRENT, @path[0])) then
begin
Result := IncludeTrailingPathDelimiter(path);
end
else
Result := '';
end;

In VCL app I get this folder path: C:\Users\user-name\AppData\Local\.

When I call the same function from service app I get this path (Win10):

C:\Windows\System32\config\systemprofile\AppData\Local\

Does anyone know how can I get folder path for service app if I call this function from VCL app? (from VCL app I need to copy some files into appdata\local folder used by a service app).

I understand I can get System32 folder path and manually add config\systemprofile\AppData\Local, but is there a more appropriate way?

Any pointers appreciated.
Thanks.

Comments

  1. It didn't write there though. It wrote to the virtual store. This is very important foundational knowledge. You need to know how all of this works. Don't ignore my comment. Or pain will ensue down the line.

    ReplyDelete
  2. David Heffernan I never ignore what you say :)

    ReplyDelete
  3. Problem solved. Using CSIDL_COMMON_APPDATA from now on.

    Thanks everybody!

    ReplyDelete

Post a Comment