user3142056
user3142056

Reputation: 347

Can't get Inno Setup postinstall Run item to runasoriginaluser

I am testing an Inno Setup in Windows 10.
I have PrivilegesRequired=lowest

In the [Run] section with postinstall I launch an Excel workbook.
This workbook makes changes to the Excel environment for the user that launched Excel.
By default, that user is the standard user, which is what I want.
But if run with right-click elevated privilege, that user is the admin user.
How can I force Excel to launch for the standard user?

I tried the flags runasoriginaluser and runascurrentuser, but neither of these would force Excel to run for the standard user.

Upvotes: 1

Views: 447

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202088

If you explicitly run the installer as Administrator, there's no way to access the user session. (Note that it's not an Inno Setup limitation, it's how Windows works.)

All you can do is to detect the Administrator privileges and notify the user not run the installer as Administrator.

[Code]

function InitializeSetup(): Boolean;
begin
  Result := True;

  if (GetWindowsVersion >= $05010000) and
     IsAdminLoggedOn then
  begin
    MsgBox('Do not run this installer "As Administrator".', mbError, MB_OK);
    Result := False;
  end;
end;

For details, see Installing application for currently logged in user from Inno Setup installer running as Administrator.

Upvotes: 1

Related Questions