Inno Setup - Registering components as an administrator

Based on the excellent installer for the Excel add-in (Daniel XL Toolbox), I created an installation file that, among other things, should register some ActiveX

[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 to add an add-on for installation, and then, before starting to register files, an administrator is checked, and if the user does not have them, a message is displayed asking you to enter an administrator password so that registration can take place. I know that this can be done at the beginning of the configuration, but then the addition will not be activated if this is a standard user account. The add-on needs registered components, a standard user cannot install it correctly.

I am looking for something like this to shoot before starting registration:

 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 to any other approach

I would also be happy to understand how a domain user (Windows server) without administrator rights should continue to install addin.

+1
source share
1 answer

You can run regsvr32.exe "as an administrator" as follows:

 [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; 

Enhanced Registration


An alternative implementation is to create a sub-installer for registration only, which will require administrator privileges.

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


Or use the opposite approach. Require admin rights with

 [Setup] PrivilegesRequired=admin 

(default)

But expand the files to the user's source folder.
See My answer on Inno Setup is always installed in the AppData directory of the administrator .

+3
source

Source: https://habr.com/ru/post/915374/


All Articles