Inno Setup always installs into admin's AppData directory
From the wording of your question and if I am understanding you correctly, it sounds like this is because you are "validating with an admin account for the install to run." If this is the case and you are entering a different account (from that which you are logged in with) at the UAC prompt, the current user then actually becomes the Administrator account you just entered at the UAC prompt and not the account you are logged in with. Therefore, as long as you are being asked to elevate the installation using UAC, it will not end up in the logged in user's AppData directory.
What you may need to do is use the runasoriginaluser
function, which will use the logged in user credentials instead of the account you entered at the UAC prompt, or find what is causing the UAC elevation prompt.
See also Inno Setup Creating registry key for logged in user (not admin user).
The MSDN documentation on Installation Context may also be useful.
It should work with PrivilegesRequired=lowest
. And it's the correct approach. If it does not, we want to see a log file.
The lowest
will make the installer run within context of the current unprivileged user. Hence all constants, like {userappdata}
, {userdesktop}
, etc, will refer to the current user.
Anyway, to answer your question, you can use the code below.
But that's just for special situations, when the installer really needs administrator privileges (e.g. to register some system DLL), but still needs to deploy files for the original user. Like here: Inno Setup - Register components as an administrator.
[Files]
Source: "MyProg.exe"; DestDir: "{code:GetAppData}"
[Code]
var
AppDataPath: string;
function GetAppData(Param: string): string;
begin
Result := AppDataPath;
end;
function InitializeSetup(): Boolean;
var
Uniq: string;
TempFileName: string;
Cmd: string;
Params: string;
ResultCode: Integer;
Buf: AnsiString;
begin
AppDataPath := ExpandConstant('{userappdata}');
Log(Format('Default/Fallback application data path is %s', [AppDataPath]));
Uniq := ExtractFileName(ExpandConstant('{tmp}'));
TempFileName :=
ExpandConstant(Format('{commondocs}\appdata-%s.txt', [Uniq]));
Params := Format('/C echo %%APPDATA%% > %s', [TempFileName]);
Log(Format('Resolving APPDATA using %s', [Params]));
Cmd := ExpandConstant('{cmd}');
if ExecAsOriginalUser(Cmd, Params, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
(ResultCode = 0) then
begin
if LoadStringFromFile(TempFileName, Buf) then
begin
AppDataPath := Trim(Buf);
Log(Format('APPDATA resolved to %s', [AppDataPath]));
end
else
begin
Log(Format('Error reading %s', [TempFileName]));
end;
DeleteFile(TempFileName);
end
else
begin
Log(Format('Error %d resolving APPDATA', [ResultCode]));
end;
Result := True;
end;
More similar questions:
- Inno Setup Using {localappdata} for logged in user
- Inno Setup - puts user files in admin documents