Inno Setup - Register components as an administrator

前端 未结 1 1485
情书的邮戳
情书的邮戳 2020-12-20 07:23

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

[Fi         


        
相关标签:
1条回答
  • 2020-12-20 07:33

    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;
    


    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.

    0 讨论(0)
提交回复
热议问题