Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

excel - Inno Setup - Register components as an administrator

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:sourcepathMSCOMCTL.OCX"; 
    DestDir: "userspublicEzPasteFiles"; Flags: regserver      
Source: "c:sourcepathDAS_AX_Knob.dll"; 
    DestDir: "userspublicEzPasteFiles"; Flags: regserver    
Source: "c:sourcepathGIF89.DLL"; 
    DestDir: "userspublicEzPasteFiles"; 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...