Mixed Admin/non-Admin with driver install if needed

85 views
Skip to first unread message

Franz Leu

unread,
Oct 15, 2024, 7:54:51 AMOct 15
to innosetup
Hi
We have an installer that so far runs in Admin mode. We now have a request that updates can be installed without Admin credentials.

If not already present (we detect), we also install "vc redist" and a driver needed.
That said, for the first install, we need to have Admin mode due to the drivers. Subsequent updates/installs may run in non-Admin if the correct destination had been selected by the first install.

How would I best do this?
Thanks for any hints.
McL

Bill Stewart

unread,
Oct 15, 2024, 4:18:05 PMOct 15
to innosetup
If your installer works correctly for non-admin users, I would keep it that way and only elevate if the driver is not installed and needs to be installed (or upgraded).

Jernej Simončič

unread,
Oct 15, 2024, 5:30:37 PMOct 15
to Franz Leu on [innosetup]

On Tuesday, October 15, 2024, 12:50:14, Franz Leu wrote:


How would I best do this?

There's no built-in way in Inno to do this. I needed something similar when creating an installer for GIMP help files – since GIMP can be installed both per-user, or per-machine, the help installer needed a way to install help files in both locations if necessary. I solved this by having the installer run itself multiple times, making use of PrivilegesRequiredOverridesAllowed=commandline – you can look at what exactly the install script does here.

 

-- 
< Jernej Simončič ><><><><>< https://eternallybored.org/ >


Paper is always strongest at the perforations.
       -- Corry's Law

Gavin Lambert

unread,
Oct 16, 2024, 2:44:00 AMOct 16
to innosetup
On Wednesday, October 16, 2024 at 12:54:51 AM UTC+13 Franz Leu wrote:
We have an installer that so far runs in Admin mode. We now have a request that updates can be installed without Admin credentials.

If not already present (we detect), we also install "vc redist" and a driver needed.
That said, for the first install, we need to have Admin mode due to the drivers. Subsequent updates/installs may run in non-Admin if the correct destination had been selected by the first install.

The way to do this sort of thing is to create an "inner" PrivilegesRequired=admin installer, while leaving the "outer" PrivilegesRequired=lowest installer to install the app itself, and only run the inner installer if needed.  This avoids having the app be installed in admin-only locations that can't be updated later -- but you have to check for failure to run the admin installer, because the user may cancel the UAC prompt or otherwise be unable to install it.  Running it from [Code] PrepareToInstall may be better in that regard than running it from [Run].

Despite numerous apps to the contrary, it is generally considered safer to install apps as admin and not allow them to be updated without admin permissions, however -- this reduces the risk that malware can infect the executables (not entirely, of course, but it does at least need to pass a UAC gate).

Franz Leu

unread,
Oct 16, 2024, 4:25:05 AMOct 16
to innosetup
Thanks to all for the thoughts and inputs.
I'll give it a try and post back with my mileage and/or additional questions.

Franz Leu

unread,
Oct 21, 2024, 11:39:33 AMOct 21
to innosetup
Hi
Changed the setup to PrivilegesRequired=lowest. Now trying to detect if driver/VC needs to be installed or are already there with functions that were already in the script and used with check in the file section.
However, nothing kicks in and still asks for language and more just to then crashes when it tries to start copying.
Any idea what I am doing wrong?
Section where it seems to crash

procedure CurStepChanged(CurStep: TSetupStep);
var
mres : integer;
begin
  case CurStep of
  ssInstall:
    begin
      if (VCRedistNeedsInstall or IsSIESingleThreadAPINeedsInstall) then
        begin
          if MsgBox(ExpandConstant('{cm:ConfirmAdminCredentialsAvailable'), mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = IDNO then
          begin
            MsgBox(ExpandConstant('{cm:CloseMissingAdmin'), mbError, MB_OK);
            Abort;
          end;
        end;

      .....



Thanks
Franz

Franz Leu

unread,
Oct 21, 2024, 12:27:23 PMOct 21
to innosetup
Never mind ... sorry ... found it and it works.

Gavin Lambert

unread,
Oct 21, 2024, 6:00:55 PMOct 21
to innosetup
On Tuesday, October 22, 2024 at 4:39:33 AM UTC+13 Franz Leu wrote:
procedure CurStepChanged(CurStep: TSetupStep);

As I mentioned earlier, it's better to do that sort of check (which can report failure) from PrepareToInstall instead of CurStepChanged -- there's an explicitly defined method to report an error message and fail the installation.

But actually there's not really much point in asking that via MsgBox at that point -- PrepareToInstall is also where you should run the admin installer if needed, so you can just run it and report an error if it fails to run.

If you want to have a MsgBox to ask someone to confirm whether they have admin or not as well, it would be better to put that earlier in the setup process.

Bill Stewart

unread,
Oct 22, 2024, 9:19:47 AMOct 22
to innosetup
On Monday, October 21, 2024 at 9:39:33 AM UTC-6 Franz Leu wrote:

Changed the setup to PrivilegesRequired=lowest. Now trying to detect if driver/VC needs to be installed or are already there with functions that were already in the script and used with check in the file section.
However, nothing kicks in and still asks for language and more just to then crashes when it tries to start copying.
Any idea what I am doing wrong?
Section where it seems to crash

procedure CurStepChanged(CurStep: TSetupStep);
var
mres : integer;
begin
  case CurStep of
  ssInstall:
    begin
      if (VCRedistNeedsInstall or IsSIESingleThreadAPINeedsInstall) then
        begin
          if MsgBox(ExpandConstant('{cm:ConfirmAdminCredentialsAvailable'), mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = IDNO then
          begin
            MsgBox(ExpandConstant('{cm:CloseMissingAdmin'), mbError, MB_OK);
            Abort;
          end;
        end;

      .....


As Gavin said,  the usual recommendation is to use PrepareToInstall rather than NextButtonClick.

I would also point out that MsgBox can be problematic if the user requests a silent install. If you really need to use MsgBox, I would recommend using it only when WizardSilent returns false.

Jernej Simončič

unread,
Oct 22, 2024, 9:45:39 AMOct 22
to 'Bill Stewart' via innosetup on [innosetup]

On Tuesday, October 22, 2024, 15:19:47, 'Bill Stewart' via innosetup wrote:


I would also point out that MsgBox can be problematic if the user requests a silent install. If you really need to use MsgBox, I would recommend using it only when WizardSilent returns false.

-- 
< Jernej Simončič ><><><><>< https://eternallybored.org/ >


In a free market good money always drives bad money out of circulation.
       -- Baxter's Third Law of Free Market
Reply all
Reply to author
Forward
0 new messages