1

Based on the excellent Excel add-in installer (Daniel's XL Toolbox), I have built a setup file that among other things needs to register some ActiveX's

[Files]
; The include file makes adds all .XLA and .XLAM files contained in the
; SOURCEDIR to the project.

Source: "c:\source\path\MSCOMCTL.OCX"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver      
Source: "c:\source\path\DAS_AX_Knob.dll"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver    
Source: "c:\source\path\GIF89.DLL"; \
    DestDir: "\users\public\EzPasteFiles"; Flags: regserver 

I need the addin to install, then before starting to register the files a check is done about administrator rights and if the user has none, a message is displayed asking for entering the admin password so that registration can take place. I am aware that it can be done at the beginning of the setup, but then the addin will not be activated, if it is a standard user account. The addin needs registered components, a standard user can't install it properly.

I am looking for something like this to fire before the registration starts:

MyProgChecked :=  not(IsAdminLoggedOn or IsPowerUserLoggedOn); 
if MyProgChecked = True then
begin
  MsgBox(
    'Kindly notice:' #13#13 
    'It seems as you are not looged as an administrator' #13#13
    'Please abort and reinstall EzPaste AS an administrator' #13#13
    '(To install As an Adminstrator, just save the exe setup anywhere then Right Click on it to get to this feature or ask your IT administrator for proper directives)',
    mbConfirmation, MB_OK);
  { Popup message asking for Pwd }
  ExitProcess(0); 
end;

I am naturally open for any other approach

I'll be glad also to understand how a domain user (Windows server) without admin rights should proceed to install the addin.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3387046
  • 449
  • 1
  • 4
  • 19
  • I do not understand what you want - First you write *"I am aware that it can be done at the beginning of the setup"* - But then it seems to me, that your pseudo code suggests exactly that - to restart the installer "as admin", so that the user is asked for admin credentials + Also I do not understand *"but then the addin will not be activated if it is a standard user account"* - Can you elaborate on that? – Martin Prikryl Apr 04 '17 at 20:34
  • As the addin needs registered components,a standard user can't install it properly. For that, the standard user needs to run the setup as an administrator, but then the addin will be installed in the admin account and will not load in the Excel of the standard user. So that I was thinking to install without any privilege and to elevate to admin only for the registration which I assume take place at the end of the installation – user3387046 Apr 04 '17 at 22:03
  • *"but then the addin will be installed in the admin account and will not load in the Excel of the standard user."* - What does that installation involve? Maybe you should give us some background regarding Excel addin installation. - What you ask for is doable. But I find it wrong to allow the user to nearly complete the installation, asking for admin privileges only at the end. What if the user does not have admin password? Whole installation is pointless then. You should ask at the beginning. But install for the user, not admin. - Though, is there really no way to install for all users? – Martin Prikryl Apr 05 '17 at 06:19
  • As I said, if asked at the beginning and installation is done As an admin with password, the Excel addin registers in the admin user account and not in that of the standard user. – user3387046 Apr 05 '17 at 20:56
  • The addin is located at (c:\Users\avibe_000\AppData\Roaming\Microsoft\AddIns\) for admin user and (c:\Users\Standard User\AppData\Roaming\Microsoft\AddIns\) for Standard User – user3387046 Apr 05 '17 at 21:05
  • Does my answer help? – Martin Prikryl Apr 07 '17 at 09:04

1 Answers1

4

You can execute regsvr32.exe "as administrator", this way:

[Files]
Source: "MyDll.dll"; DestDir: "{app}"; AfterInstall: RegMyDll

[Code]

procedure RegMyDll;
var
  Path: string;
  RegSvr: string;
  Params: string;
  Registered: Boolean;
  ErrorCode: Integer;
begin
  Path := ExpandConstant(CurrentFilename);
  RegSvr := 'regsvr32.exe';
  Params := Format('/s "%s"', [Path]);
  Log(Format('Registering %s using "%s" %s', [Path, RegSvr, Params]));
  Registered :=
    ShellExec('runas', RegSvr, Params, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
  if Registered and (ErrorCode = 0) then
  begin
    Log(Format('Registered %s', [Path]));
  end
    else
  begin
    MsgBox(Format('Registering %s failed with code %d', [Path, ErrorCode]), mbError, MB_OK);
  end;
end;

Elevated registration


Alternative implementation is to create subinstaller for the registration only that will require Administrator privileges.

For a similar example, see Inno Setup - Access unprivileged account folders from installer that requires privileges.


Or use an opposite approach. Require administrator privileges using

[Setup]
PrivilegesRequired=admin

(which is default)

But deploy files to the original user folder.
See my answer to Inno Setup always installs into admin's AppData directory.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992